TetrisBot: Rename Cell value constants.

This commit is contained in:
2019-11-10 18:32:39 +01:00
parent 7b97e3249e
commit 0385c04136

View File

@@ -64,15 +64,15 @@ namespace VAR.ScreenAutomation.Bots
SearchBestAction(); SearchBestAction();
// Show information // Show information
_workGrid0.SampleOther(_grid, TetrisGrid.Solid, TetrisGrid.Solid); _workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
if (_shapeFound) if (_shapeFound)
{ {
_currentShape[0].PutOnGrid(_workGrid0, _shapeX, _shapeY, TetrisGrid.Empty); _currentShape[0].PutOnGrid(_workGrid0, _shapeX, _shapeY, TetrisGrid.CellEmpty);
_currentShape[_bestRotation].Drop(_workGrid0, _shapeX + _bestXOffset, _shapeY, TetrisGrid.ShapeA); _currentShape[_bestRotation].Drop(_workGrid0, _shapeX + _bestXOffset, _shapeY, TetrisGrid.CellShapeA);
_currentShape[0].PutOnGrid(_workGrid0, _shapeX, _shapeY, TetrisGrid.ShapeB); _currentShape[0].PutOnGrid(_workGrid0, _shapeX, _shapeY, TetrisGrid.CellShapeB);
} }
_workGrid0.Draw(bmpInput, 0.75f); _workGrid0.Draw(bmpInput, 0.75f);
_workGrid0.SampleOther(_grid, TetrisGrid.Solid, TetrisGrid.Solid); _workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
_workGrid0.RemoveGround(); _workGrid0.RemoveGround();
_workGrid0.Draw(bmpInput, 0.25f); _workGrid0.Draw(bmpInput, 0.25f);
@@ -81,7 +81,7 @@ namespace VAR.ScreenAutomation.Bots
private void SearchShape() private void SearchShape()
{ {
_workGrid0.SampleOther(_grid, TetrisGrid.Solid, TetrisGrid.Solid); _workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
_workGrid0.RemoveGround(); _workGrid0.RemoveGround();
_shapeFound = false; _shapeFound = false;
for (int y = 0; y < _grid.Height; y++) for (int y = 0; y < _grid.Height; y++)
@@ -91,8 +91,8 @@ namespace VAR.ScreenAutomation.Bots
TetrisShape matchedShape = TetrisShape.DefaultShapes.FirstOrDefault(s => s.MatchOnGrid(_workGrid0, x, y)); TetrisShape matchedShape = TetrisShape.DefaultShapes.FirstOrDefault(s => s.MatchOnGrid(_workGrid0, x, y));
if (matchedShape != null) if (matchedShape != null)
{ {
_workGrid1.SampleOther(_workGrid0, TetrisGrid.Solid, TetrisGrid.Solid); _workGrid1.SampleOther(_workGrid0, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
matchedShape.PutOnGrid(_workGrid1, x, y, TetrisGrid.Empty); matchedShape.PutOnGrid(_workGrid1, x, y, TetrisGrid.CellEmpty);
if (matchedShape.CheckIntersection(_workGrid1, x, y + 1)) { continue; } if (matchedShape.CheckIntersection(_workGrid1, x, y + 1)) { continue; }
// Shape found // Shape found
@@ -118,7 +118,7 @@ namespace VAR.ScreenAutomation.Bots
_bestRotation = 0; _bestRotation = 0;
if (!_shapeFound) if (!_shapeFound)
{ {
_workGrid0.SampleOther(_grid, TetrisGrid.Solid, TetrisGrid.Solid); _workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
return; return;
} }
@@ -127,10 +127,10 @@ namespace VAR.ScreenAutomation.Bots
{ {
for (int x = 0; x < _grid.Width; x++) for (int x = 0; x < _grid.Width; x++)
{ {
_workGrid0.SampleOther(_grid, TetrisGrid.Solid, TetrisGrid.Solid); _workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
_currentShape[0].PutOnGrid(_workGrid0, _shapeX, _shapeY, TetrisGrid.Empty); _currentShape[0].PutOnGrid(_workGrid0, _shapeX, _shapeY, TetrisGrid.CellEmpty);
if (_currentShape[rotation].Drop(_workGrid0, x, _shapeY, TetrisGrid.ShapeA)) if (_currentShape[rotation].Drop(_workGrid0, x, _shapeY, TetrisGrid.CellShapeA))
{ {
double newEvaluation = EvaluateWorkingGrid(); double newEvaluation = EvaluateWorkingGrid();
_columnEvaluation[x] = newEvaluation; _columnEvaluation[x] = newEvaluation;
@@ -566,10 +566,10 @@ namespace VAR.ScreenAutomation.Bots
public class TetrisGrid public class TetrisGrid
{ {
public const byte Empty = 0; public const byte CellEmpty = 0;
public const byte Solid = 1; public const byte CellSolid = 1;
public const byte ShapeA = 2; public const byte CellShapeA = 2;
public const byte ShapeB = 3; public const byte CellShapeB = 3;
private int _gridWidth; private int _gridWidth;
private int _gridHeight; private int _gridHeight;
@@ -666,7 +666,7 @@ namespace VAR.ScreenAutomation.Bots
{ {
if (_grid[_gridHeight - 1][i] == 1) if (_grid[_gridHeight - 1][i] == 1)
{ {
FloodFill(i, _gridHeight - 1, Solid, Empty); FloodFill(i, _gridHeight - 1, CellSolid, CellEmpty);
} }
} }
} }
@@ -754,7 +754,7 @@ namespace VAR.ScreenAutomation.Bots
for (int i = 0; i < _gridWidth; i++) for (int i = 0; i < _gridWidth; i++)
{ {
int j = 0; int j = 0;
while (j < _gridHeight && _grid[j][i] == Empty) { j++; } while (j < _gridHeight && _grid[j][i] == CellEmpty) { j++; }
_heights[i] = _gridHeight - j; _heights[i] = _gridHeight - j;
} }
double agregateHeight = _heights.Sum(); double agregateHeight = _heights.Sum();
@@ -773,11 +773,11 @@ namespace VAR.ScreenAutomation.Bots
bool block = false; bool block = false;
for (int y = 1; y < _gridHeight; y++) for (int y = 1; y < _gridHeight; y++)
{ {
if (_grid[y][x] != Empty && IsCompleteLine(y) == false) if (_grid[y][x] != CellEmpty && IsCompleteLine(y) == false)
{ {
block = true; block = true;
} }
else if (_grid[y][x] == Empty && block) else if (_grid[y][x] == CellEmpty && block)
{ {
holes++; holes++;
} }
@@ -818,19 +818,19 @@ namespace VAR.ScreenAutomation.Bots
for (int x = 0; x < _gridWidth; x++) for (int x = 0; x < _gridWidth; x++)
{ {
Brush br = null; Brush br = null;
if (_grid[y][x] == Empty) if (_grid[y][x] == CellEmpty)
{ {
br = Brushes.Black; br = Brushes.Black;
} }
else if (_grid[y][x] == Solid) else if (_grid[y][x] == CellSolid)
{ {
br = Brushes.Blue; br = Brushes.Blue;
} }
else if (_grid[y][x] == ShapeA) else if (_grid[y][x] == CellShapeA)
{ {
br = Brushes.Red; br = Brushes.Red;
} }
else if (_grid[y][x] == ShapeB) else if (_grid[y][x] == CellShapeB)
{ {
br = Brushes.Green; br = Brushes.Green;
} }