Example #1
0
    public void GenerateBoard(BoardCellState[] cells = null)
    {
        elementPositions = new Dictionary <string, List <Vector2Int> >();
        // If a board already exist, destroy it
        DestroyBoard();
        // Initialize board
        board = new BoardCell[columns + 2, rows + 2];
        // Instantiate cells
        if (cells != null)
        {
            foreach (BoardCellState cellState in cells)
            {
                AddBoardCell(cellState.id, cellState.x, cellState.y, cellState.args);
            }
        }
        else
        {
            GenerateDefaultBoard();
        }

        nReceivers       = 0;
        nReceiversActive = 0;

        SetFocusPointOffset(new Vector3(columns / 2.0f + 0.5f, 0.0f, rows / 2.0f + 0.5f));
    }
Example #2
0
 private bool isNumber(BoardCell[,] cells, int cx, int cy, int X, int Y)
 {
     if ((cx - 1 >= 0) && (cy - 1 >= 0))
     {
         if (cells[cx - 1, cy - 1] == BoardCell.Mine)
         {
             return(true);
         }
     }
     if (cy - 1 >= 0)
     {
         if (cells[cx, cy - 1] == BoardCell.Mine)
         {
             return(true);
         }
     }
     if ((cx + 1 < X) && (cy - 1 >= 0))
     {
         if (cells[cx + 1, cy - 1] == BoardCell.Mine)
         {
             return(true);
         }
     }
     if (cx - 1 >= 0)
     {
         if (cells[cx - 1, cy] == BoardCell.Mine)
         {
             return(true);
         }
     }
     if (cx + 1 < X)
     {
         if (cells[cx + 1, cy] == BoardCell.Mine)
         {
             return(true);
         }
     }
     if ((cx - 1 >= 0) && (cy + 1 < Y))
     {
         if (cells[cx - 1, cy + 1] == BoardCell.Mine)
         {
             return(true);
         }
     }
     if (cy + 1 < Y)
     {
         if (cells[cx, cy + 1] == BoardCell.Mine)
         {
             return(true);
         }
     }
     if ((cx + 1 > X) && (cy + 1 > Y))
     {
         if (cells[cx + 1, cy + 1] == BoardCell.Mine)
         {
             return(true);
         }
     }
     return(false);
 }
Example #3
0
        public Tuple <Cell, Cell> GetTwoNextNextCells(BoardCell[,] board)
        {
            if (Start == End)
            {
                return(new Tuple <Cell, Cell>(null, null));
            }

            Cell first = null;
            var  start = Start + 2 * Direction;

            if (start.IsEmpty(board))
            {
                first = start;
            }

            Cell second = null;
            var  end    = End - 2 * Direction;

            if (end.IsEmpty(board))
            {
                second = end;
            }

            return(new Tuple <Cell, Cell>(first, second));
        }
Example #4
0
File: Board.cs Project: bdr27/c-
        public Board()
        {
            //create cell objects
            int nextID = 1;
            cells = new BoardCell[3, 3];
            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    cells[i, j] = new BoardCell()
                    {
                        row = i,
                        col = j,
                        ID = nextID++
                    };
                }
            }

            // setup the winLists for each cell
            // doing this by hand, no need to figure out a loop based dynamic-sized algorithm...
            // tictactoe is 3x3 only...
            cells[0, 0].winLists = setupWinListForCell_1();
            cells[1, 0].winLists = setupWinListForCell_4();
            cells[2, 0].winLists = setupWinListForCell_7();

            cells[0, 1].winLists = setupWinListForCell_2();
            cells[1, 1].winLists = setupWinListForCell_5();
            cells[2, 1].winLists = setupWinListForCell_8();

            cells[0, 2].winLists = setupWinListForCell_3();
            cells[1, 2].winLists = setupWinListForCell_6();
            cells[2, 2].winLists = setupWinListForCell_9();
        }
        protected virtual void Start()
        {
            if (_boardToBeUsed == null)
            {
                Debug.LogError("Board Manager requires a Board reference to create a game board.");
            }
            else
            {
                BoardPositions = new BoardCell[_boardToBeUsed.Rows, _boardToBeUsed.Columns];

                var layout = _boardInScene.GetComponent <GridLayoutGroup>();

                if (layout == null)
                {
                    Debug.LogError("Board requires a Grid Layout to be added onto the board to manage it's positions.");
                }
                else
                {
                    layout.constraintCount = _boardToBeUsed.Columns;
                }

                CreateBoard();
            }

            MoveManager.Instance.SquareSelected += MoveManager_OnSquareSelected;
        }
        private void createBoardRows(ref StringBuilder io_FullBoard, BoardCell[,] i_LogicBoardCells)
        {
            StringBuilder boardRow      = new StringBuilder();
            StringBuilder separationRow = createSeparationRow();
            Location      cardLocation;
            int           boardHeight = m_Board.Height;
            int           boardWidth  = m_Board.Width;

            for (int row = 1; row <= boardHeight; row++)
            {
                boardRow.Remove(0, boardRow.Length);
                boardRow.Append(row);
                boardRow.Append(' ');
                boardRow.Append('|');
                for (int column = 1; column <= boardWidth; column++)
                {
                    boardRow.Append(' ');
                    if (i_LogicBoardCells[row - 1, column - 1].IsHidden)
                    {
                        boardRow.Append(' ');
                    }
                    else
                    {
                        cardLocation = new Location(column - 1, row - 1);
                        boardRow.Append(m_Board.GetCardValue(cardLocation));
                    }

                    boardRow.Append(' ');
                    boardRow.Append('|');
                }

                assembleFullBoard(ref io_FullBoard, boardRow);
                assembleFullBoard(ref io_FullBoard, separationRow);
            }
        }
Example #7
0
        private Cell NextCellWithType(int i, BoardCell[,] board)
        {
            var cell = NextCell(i);

            cell.BoardCell = !cell.InTheBoard ? BoardCell.Invalid : board[cell.X, cell.Y];
            return(cell);
        }
Example #8
0
            private bool Init()
            {
                bool result = false;

                cells = new BoardCell[X, Y];
                Dir dir = Dir.Righ;
                int cx = 0, cy = 0;
                int ndx = 0;

                cells[cx, cy] = BoardCell.Mine;
                int mineLeft = M - 1;

                while (ndx != X * Y - 1)
                {
                    if (canGo(dir, cx, cy, X, Y))
                    {
                        if (go(dir, ref cx, ref cy, X, Y, ref mineLeft))
                        {
                            result = true;
                        }
                        ndx++;
                    }
                    else
                    {
                        dir = changeDir(dir);
                    }
                }
                return(result);
            }
Example #9
0
 public Board(Board i_Other)
 {
     this.r_Rows    = i_Other.r_Rows;
     this.r_Columns = i_Other.r_Columns;
     this.r_Board   = new BoardCell[r_Rows, r_Columns];
     copyBoardCells(i_Other);
 }
Example #10
0
 public Game(BoardCell[,] board)
 {
     this.board = (BoardCell[, ])board.Clone();
     sw         = new Stopwatch();
     GameStates = new List <GameState>();
     Depth      = DefaultDepth;
 }
Example #11
0
        private void swap(Point p1, Point p2, BoardCell[,] cells)
        {
            BoardCell tmp = cells[p1.Y, p1.X];

            cells[p1.Y, p1.X] = cells[p2.Y, p2.X];
            cells[p2.Y, p2.X] = tmp;
        }
Example #12
0
 private void CalcProps(BoardCell[,] board)
 {
     CalcStart();
     CalcEnd();
     CalcDirection();
     CalcNextAndPrev(board);
 }
Example #13
0
 public virtual List <Cell> GetAcceptableCells(
     BoardCell[,] boardCells,
     Cell currentCell,
     bool needToCheckShah = true)
 {
     throw new NotImplementedException();
 }
Example #14
0
 public Board()
 {
     sizeX = 8;
     sizeY = 8;
     cells = new BoardCell[sizeX, sizeY];
     createCells();
 }
Example #15
0
 public BoardStateBase(List <Line> myLines, List <Line> oppLines, BoardCell myCellType, BoardCell[,] board)
 {
     MyLines    = myLines;
     OppLines   = oppLines;
     MyCellType = myCellType;
     Board      = board;
 }
Example #16
0
        internal Board(int i_BoardSize, Player i_Player1, Player i_Player2)
        {
            m_BoardArray = new BoardCell[i_BoardSize, i_BoardSize];
            m_BoardSize  = m_BoardArray.GetUpperBound(0);

            for (int i = 0; i < i_BoardSize; i++)
            {
                for (int j = 0; j < i_BoardSize; j++)
                {
                    if (i < ((i_BoardSize / 2) - 1) && (i + j) % 2 != 0)
                    {
                        m_BoardArray[i, j]         = new BoardCell(new Location(i, j));
                        m_BoardArray[i, j].Checker = new Checker(eCheckerType.O, i_Player1);
                    }
                    else if (i >= ((i_BoardSize / 2) + 1) && (i + j) % 2 != 0)
                    {
                        m_BoardArray[i, j]         = new BoardCell(new Location(i, j));
                        m_BoardArray[i, j].Checker = new Checker(eCheckerType.X, i_Player2);
                    }
                    else
                    {
                        m_BoardArray[i, j] = new BoardCell(new Location(i, j));
                    }
                }
            }
        }
Example #17
0
        public void PrintBoard(BoardCell[,] i_GameBoard, Player[] i_Players)
        {
            // Ex02.ConsoleUtils.Screen.Clear();
            string stringToWrite;

            PrintPlayers(i_Players);
            Console.Write("  ");
            for (int j = k_One; j <= m_Size; j++)
            {
                Console.Write(j + "   ");
            }

            for (int i = k_Zero; i < m_Size; i++)
            {
                Console.Write(System.Environment.NewLine);
                Console.Write(i + k_One + "|");
                for (int j = k_Zero; j < m_Size; j++)
                {
                    stringToWrite = i_GameBoard[i, j].m_IsVisible ? " " + i_GameBoard[i, j].m_SignOfCell + " |" : "   |";
                    Console.Write(stringToWrite);
                }

                Console.Write(System.Environment.NewLine + " =");
                for (int j = k_One; j <= m_Size; j++)
                {
                    Console.Write("====");
                }
            }

            Console.WriteLine();
        }
Example #18
0
 public Game(int width, int height)
 {
     this.width  = width;
     this.height = height;
     board       = new BoardCell[width, height];
     sw          = new Stopwatch();
 }
Example #19
0
        Cell GetCastlingCell(
            BoardCell[,] boardCells,
            int rookStartColumn)
        {
            Rook rook = boardCells[StartRow, rookStartColumn].Chessman as Rook;

            if (rook == null)
            {
                return(null);
            }

            if (rook.Moved)
            {
                return(null);
            }

            if (!CellsBetweenRookAndKingAreEmpty(boardCells, rookStartColumn))
            {
                return(null);
            }

            var isLeftCastling = rookStartColumn == 0;

            if (!KingCellsAreNotUnderShahWhileCastling(boardCells, isLeftCastling))
            {
                return(null);
            }

            return(new Cell(StartRow, GetNewKingColumn(isLeftCastling)));
        }
Example #20
0
 public Board(int i_RowsInBoard, int i_ColumnsInBoard)
 {
     this.r_Rows    = i_RowsInBoard;
     this.r_Columns = i_ColumnsInBoard;
     r_Board        = new BoardCell[r_Rows, r_Columns];
     initializeBoard();
 }
Example #21
0
        List <Cell> GetCastlingAcceptableCells(
            BoardCell[,] boardCells,
            Cell currentCell)
        {
            var acceptableCells = new List <Cell>();

            if (Moved)
            {
                return(acceptableCells);
            }

            if (IsCellUnderShah(boardCells, currentCell, Color))
            {
                return(acceptableCells);
            }

            var rookStartColumns = new int[] { 0, 7 };

            foreach (var rookStartColumn in rookStartColumns)
            {
                var castlingCell = GetCastlingCell(boardCells, rookStartColumn);
                if (castlingCell != null)
                {
                    acceptableCells.Add(castlingCell);
                }
            }

            return(acceptableCells);
        }
Example #22
0
        public override List <Cell> GetAcceptableCells(
            BoardCell[,] boardCells,
            Cell currentCell,
            bool needToCheckShah = true)
        {
            Direction[] possibleDirections =
            {
                new Direction {
                    Row = -1, Column = -1
                },
                new Direction {
                    Row = -1, Column = 1
                },
                new Direction {
                    Row = 1, Column = -1
                },
                new Direction {
                    Row = 1, Column = 1
                }
            };

            var acceptableCells = GetAcceptableCellsForDirections(boardCells, possibleDirections, currentCell);

            if (needToCheckShah)
            {
                AdjustAcceptableCellsInCaseShah(boardCells, acceptableCells, currentCell);
            }

            return(acceptableCells);
        }
Example #23
0
        public Tuple <Cell, Cell> GetTwoNextCells(BoardCell[,] board)
        {
            if (Start == End)
            {
                Cell move;
                if (LineOfOneCase(board, out move))
                {
                    return(new Tuple <Cell, Cell>(move, move));
                }
            }

            Cell first = null;
            var  start = Start + Direction;

            if (start.IsEmpty(board))
            {
                first = start;
            }

            Cell second = null;
            var  end    = End - Direction;

            if (end.IsEmpty(board))
            {
                second = end;
            }

            return(new Tuple <Cell, Cell>(first, second));
        }
Example #24
0
        public override List <Cell> GetAcceptableCells(
            BoardCell[,] boardCells,
            Cell currentCell,
            bool needToCheckShah = true)
        {
            var acceptableCells = new List <Cell>();

            Movement[] possibleMovements =
            {
                new Movement {
                    Row = -1, Column = -2
                },
                new Movement {
                    Row = -1, Column = 2
                },
                new Movement {
                    Row = 1, Column = -2
                },
                new Movement {
                    Row = 1, Column = 2
                },
                new Movement {
                    Row = -2, Column = -1
                },
                new Movement {
                    Row = -2, Column = 1
                },
                new Movement {
                    Row = 2, Column = -1
                },
                new Movement {
                    Row = 2, Column = 1
                },
            };

            foreach (var possibleMovement in possibleMovements)
            {
                var testRow    = currentCell.Row + possibleMovement.Row;
                var testColumn = currentCell.Column + possibleMovement.Column;
                var cell       = new Cell(testRow, testColumn);

                if (!IsCellInBounds(cell))
                {
                    continue;
                }

                if (IfEmptyOrEnemy(boardCells, testRow, testColumn))
                {
                    acceptableCells.Add(cell);
                }
            }

            if (needToCheckShah)
            {
                AdjustAcceptableCellsInCaseShah(boardCells, acceptableCells, currentCell);
            }

            return(acceptableCells);
        }
        public void PrintBoard(BoardCell[,] i_LogicBoardCells)
        {
            StringBuilder fullBoard = new StringBuilder();

            createFrameRow(ref fullBoard);
            createBoardRows(ref fullBoard, i_LogicBoardCells);
            Console.WriteLine(fullBoard);
        }
Example #26
0
 private static bool ExistSide(int x, int y, BoardCell[,] board, BoardCell kind)
 {
     return
         (IsCellEqual(x - 1, y, board, kind) ||
          IsCellEqual(x + 1, y, board, kind) ||
          IsCellEqual(x, y + 1, board, kind) ||
          IsCellEqual(x, y - 1, board, kind));
 }
Example #27
0
 void TestMoveChessman(
     BoardCell[,] chessboard,
     Cell oldCell,
     Cell newCell)
 {
     chessboard[newCell.Row, newCell.Column].Chessman = chessboard[oldCell.Row, oldCell.Column].Chessman;
     chessboard[oldCell.Row, oldCell.Column].Chessman = null;
 }
Example #28
0
        private void makeSolvable()
        {
            Point[] hint;
            BoardCell[,] cellsCopy = new BoardCell[numCells_v, numCells_h];
            for (int i = 0; i < numCells_v; i++)
            {
                for (int j = 0; j < numCells_h; j++)
                {
                    cellsCopy[i, j] = new BoardCell(cells[i, j].getType());
                }
            }

            while (numCleared < numTiles)
            {
                //ÈùÆ® ¾ò±â
                while ((hint = getHint()) != null)
                {
                    clearPair(hint[0], hint[1], null);
                }
                if (numCleared == numTiles)
                {
                    break;
                }

                int cell1 = -1, cell2 = -1, cell3 = -1;
                int cell1Val = -1, iVal;
                for (int i = 0; i < numCells; i++)
                {
                    iVal = getCell(i).getType();
                    if (iVal != BoardCell.CELL_EMPTY)
                    {
                        if (cell1 == -1)
                        {
                            cell1    = i;
                            cell1Val = iVal;
                        }
                        else if (iVal == cell1Val)
                        {
                            cell2 = i;
                        }
                        else if (getPath(cell1, i) != null)
                        {
                            cell3 = i;
                        }
                        if (cell1 > -1 && cell2 > -1 && cell3 > -1)
                        {
                            break;
                        }
                    }
                }
                swap(cell2, cell3);
                swap(cell2, cell3, cellsCopy);
                clearPair(cell1, cell3, null);
            }
            cells      = cellsCopy;
            numCleared = 0;
        }
Example #29
0
        public ChessBoard(string serializedChessboard)
        {
            ChessBoard deserialisedChessBoard = JsonConvert.DeserializeObject <ChessBoard>(serializedChessboard);

            ChessBoardBuilder.NormilizedBoardCells(deserialisedChessBoard.BoardCells);

            BoardCells = deserialisedChessBoard.BoardCells;
            Status     = deserialisedChessBoard.Status;
        }
Example #30
0
        static void SetStartPositionsForPawns(BoardCell[,] boardCells, Color color)
        {
            var row = color == Color.Black ? 1 : 6;

            for (int column = 0; column <= 7; column++)
            {
                boardCells[row, column] = new BoardCell(row, column, new Pawn(color));
            }
        }
Example #31
0
        BoardCell[,] GetDeepCopyOfBoardCells(BoardCell[,] boardCells)
        {
            var serializedChessboard  = JsonConvert.SerializeObject(boardCells);
            var deserializedBoarCells = JsonConvert.DeserializeObject <BoardCell[, ]>(serializedChessboard);

            ChessBoardBuilder.NormilizedBoardCells(deserializedBoarCells);

            return(deserializedBoarCells);
        }
Example #32
0
        /// <summary>
        /// Игровое поле
        /// </summary>
        /// <param name="width">высота в ячейках</param>
        /// <param name="height">ширина в ячейках</param>
        /// <param name="numMines">количество мин</param>
        public GameBoard(int width, int height, int numMines)
        {
            GameBoardWidth = width;
            GameBoardHeight = height;
            NumberMines = numMines;
            NumberCells = GameBoardHeight * GameBoardWidth;

            boardSquares = new BoardCell[width, height];

            ClearBoard();
        }
Example #33
0
 public GameBoard()
 {
     //create cell objects
     cells = new BoardCell[3, 3];
     for (int i = 0; i < 3; ++i)
     {
         for (int j = 0; j < 3; ++j)
         {
             cells[i, j] = new BoardCell()
             {
                 row = i,
                 col = j,
             };
         }
     }
     SetupWinLists();
 }
Example #34
0
 // Private Methods
 private void InitializeBoard()
 {
     this.m_Board = new BoardCell[this.m_NumberOfColumns, this.m_NumberOfRows];
     InitializeCells();
 }
    public Estado(BoardCell[,] board, int nivel, int alto, int ancho, Equipo equipo)
    {
        this.board = board;
        this.alto = alto;
        this.ancho = ancho;
        this.equipo = equipo;

        // Indicar la cantidad de fichas en base al nivel
        if (nivel == 1 || nivel == 2)
        {
            cantidadFichas = nivel;
        }
        else if (nivel == 3)
        {
            cantidadFichas = 5;
        }

        jugadores = new BoardCell[cantidadFichas];
        oponentes = new BoardCell[cantidadFichas];

        // Inicializar la lista de jugadores, oponentes y pelota
        int ij = 0;
        int io = 0;
        for (int i = 1; i < alto - 1; i++)
        {
            for (int j = 0; j < ancho; j++)
            {
                if (board[i, j].ficha == TipoFicha.Pelota)
                {
                    pelota = board[i, j];
                }
                if (board[i, j].fichaEquipo() == equipo)
                {
                    jugadores[ij] = board[i, j];
                    ij += 1;
                    // En caso que sea el arquero del equipo
                    if (board[i,j].esArquero(false))
                    {
                        arqueroJugador = board[i,j];
                    }
                }
                else if (board[i, j].fichaEquipo() != Equipo.Ninguno)
                {
                    oponentes[io] = board[i, j];
                    io += 1;
                    // En caso que sea el arquero del equipo
                    if (board[i,j].esArquero(false))
                    {
                        arqueroOponente = board[i,j];
                    }
                }
            }
        }
    }
Example #36
0
 public void Init()
 {
     cells = new BoardCell[rowCount, colCount];
     for (int i = 0; i < rowCount; i++)
     {
         for (int j = 0; j < colCount; j++)
         {
             cells[i, j] = new BoardCell(i,j);
         }
     }
 }