Exemple #1
0
        public static BoardState getEmptyBord()
        {
            eSquare[,] empty = {
                { eSquare.Empty, eSquare.Empty, eSquare.Empty},
                { eSquare.Empty, eSquare.Empty, eSquare.Empty},
                { eSquare.Empty, eSquare.Empty, eSquare.Empty} };

            BoardState emptyBoard = new BoardState
            {
                currentBoard = empty
            };
            return emptyBoard;
        }
Exemple #2
0
        public void setImageBoxes(BoardState bState)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    switch(bState.currentBoard[i, j])
                    {
                        case eSquare.Cross:
                            pictureBoxs[(i*3) + j].Image = cross;
                            break;
                        case eSquare.Naught:
                            pictureBoxs[(i * 3) + j].Image = nought;
                            break;
                        case eSquare.Empty:
                            pictureBoxs[(i * 3) + j].Image = null;
                            break;
                    }

                }
            }
        }
Exemple #3
0
        public List<BoardState> getAllNextMoves()
        {
            List<BoardState> allMoves = new List<BoardState>(CountEmptySpaces());
            Point lastPoint = new Point(0,0);
            if (CheckForWin() != null) return allMoves; // If someone has won, return the list empty since there are no futher moves

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (currentBoard[i, j] == eSquare.Empty)
                    {
                        BoardState newMove = new BoardState((eSquare[,]) currentBoard.Clone());
                        newMove.setSquare(i, j, currentPlayerTurn == ePlayer.Cross ? eSquare.Cross : eSquare.Naught);
                        newMove.setCurrentPlayerTurn(currentPlayerTurn == ePlayer.Cross ? ePlayer.Naught : ePlayer.Cross);
                        allMoves.Add(newMove);
                    }

                }
            }
            return allMoves;
        }