Example #1
0
        public static ZhedBoard SpreadTile(ZhedBoard board, Coords coords, Func <Coords, Coords> moveFunction)
        {
            int tileValue = board.TileValue(coords);

            if (tileValue <= 0)
            {
                return(board);
            }

            ZhedBoard newBoard = new ZhedBoard(board);

            newBoard.SetTile(coords, USED_TILE);
            newBoard.boardValue += 2 * tileValue;
            newBoard.UpdateValueTiles(coords);
            while (tileValue > 0)
            {
                coords = moveFunction(coords);
                if (!newBoard.inbounds(coords))
                {
                    break;
                }

                switch (newBoard.TileValue(coords))
                {
                case EMPTY_TILE: newBoard.SetTile(coords, USED_TILE);  tileValue--; break;

                case FINISH_TILE: newBoard.SetTile(coords, WINNER_TILE); newBoard.isOver = true; break;

                default: break;
                }
            }

            return(newBoard);
        }