public GameResult DoAction(Direction direction) { int[,] oldBoard = new int[SIZE, SIZE]; Array.Copy(_WorkBoard, 0, oldBoard, 0, SIZE * SIZE); GoDirection(direction); if (_WorkBoard.IsDifferent(oldBoard, SIZE, SIZE)) { if (_WorkBoard.Any(SIZE, SIZE, x => x == 0)) { InsertRandom(); } if (CheckWin()) { return(GameResult.Win); } else if (CheckLost()) { return(GameResult.Loss); } else { return(GameResult.Continue); } } else { return(GameResult.Continue); } }
public static bool IsLost(this int[,] array, int arraySideSize) { if (array.Any(arraySideSize, arraySideSize, x => x == 0)) { return(false); } for (int x = 0; x < arraySideSize; x++) { for (int y = 0; y < arraySideSize; y++) { if ((x != arraySideSize - 1 && array[x, y] == array[x + 1, y]) || (y != arraySideSize - 1 && array[x, y] == array[x, y + 1])) { return(false); } } } return(true); }
public override double CalculatePoints(int[,] grid, Direction fromDirection, int gridSideSize) { return(Coefficient * (grid.Any(Game2048.SIZE, Game2048.SIZE, (content) => content == Game2048.WIN) ? _WiningScore : 0)); }