コード例 #1
0
ファイル: TokenButton.cs プロジェクト: yarin1006/Reversi
        public void SetButtonStatus(eSignMarks i_Token)
        {
            FlatStyle = FlatStyle.Flat;
            FlatAppearance.BorderSize  = k_ThickBorder;
            FlatAppearance.BorderColor = Color.White;

            switch (i_Token)
            {
            case eSignMarks.Blank:
                BackColor = SystemColors.Control;
                FlatAppearance.BorderSize  = k_ThinBorder;
                FlatAppearance.BorderColor = Color.Gray;
                break;

            case eSignMarks.PlayerTwoToken:
                BackColor = Color.White;
                ForeColor = Color.Black;
                break;

            case eSignMarks.PlayerOneToken:
                BackColor = Color.Black;
                ForeColor = Color.White;
                break;

            default:
                throw new ArgumentException("Unrecognized mark found in board state");
            }

            Enabled = false;
        }
コード例 #2
0
        public void GetPossibleMoves(
            eSignMarks i_Token,
            out List <TokenLocation> o_AvailableMoves)
        {
            o_AvailableMoves = null;
            for (int rowN = 0; rowN < m_Board.BoardSize; ++rowN)
            {
                for (int colN = 0; colN < m_Board.BoardSize; ++colN)
                {
                    if (m_Board[rowN, colN] == eSignMarks.Blank)
                    {
                        int numberOfTokensReplaced;
                        eSignMarks[,] boardStateAfterPlacingToken;
                        m_Board.LocationToken(i_Token, rowN, colN, out boardStateAfterPlacingToken, out numberOfTokensReplaced);
                        if (numberOfTokensReplaced > 0)
                        {
                            if (o_AvailableMoves == null)
                            {
                                o_AvailableMoves = new List <TokenLocation>();
                            }

                            o_AvailableMoves.Add(new TokenLocation(rowN, colN));
                        }
                    }
                }
            }
        }
コード例 #3
0
        public void GetBestComputerMove(
            eSignMarks i_Token,
            out eSignMarks[,] o_BoardStateInBestMove)
        {
            int numberOfTokensReplacedInBestMove = 0;

            o_BoardStateInBestMove = null;
            for (int rowN = 0; rowN < m_Board.BoardSize; ++rowN)
            {
                for (int colN = 0; colN < m_Board.BoardSize; ++colN)
                {
                    if (m_Board[rowN, colN] == eSignMarks.Blank)
                    {
                        int numberOfTokensReplaced;
                        eSignMarks[,] boardStateAfterPlacingToken;
                        m_Board.LocationToken(i_Token, rowN, colN, out boardStateAfterPlacingToken, out numberOfTokensReplaced);

                        if (moveIsBetter(numberOfTokensReplaced, numberOfTokensReplacedInBestMove))
                        {
                            o_BoardStateInBestMove           = boardStateAfterPlacingToken;
                            numberOfTokensReplacedInBestMove = numberOfTokensReplaced;
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: GameBoard.cs プロジェクト: yarin1006/Reversi
 public GameBoard(int i_SizeOfTable)
 {
     CurrentTableState = new eSignMarks[i_SizeOfTable, i_SizeOfTable];
     CurrentTableState[(i_SizeOfTable / 2) - 1, (i_SizeOfTable / 2) - 1] = eSignMarks.PlayerTwoToken;
     CurrentTableState[(i_SizeOfTable / 2) - 1, (i_SizeOfTable / 2)]     = eSignMarks.PlayerOneToken;
     CurrentTableState[(i_SizeOfTable / 2), (i_SizeOfTable / 2) - 1]     = eSignMarks.PlayerOneToken;
     CurrentTableState[(i_SizeOfTable / 2), (i_SizeOfTable / 2)]         = eSignMarks.PlayerTwoToken;
 }
コード例 #5
0
ファイル: GameBoard.cs プロジェクト: yarin1006/Reversi
        public void LocationToken(eSignMarks i_Token, int i_Row, int i_Col, out eSignMarks[,] o_NewBoardStatus, out int o_NumberTokensThatReplaced)
        {
            if (i_Row >= BoardSize || i_Row >= BoardSize || CurrentTableState[i_Row, i_Col] != eSignMarks.Blank)
            {
                throw new System.InvalidOperationException("Ileagal token location");
            }

            o_NumberTokensThatReplaced = 0;
            o_NewBoardStatus           = CurrentTableState;
            foreach (eMoveDirection direction in Enum.GetValues(typeof(eMoveDirection)))
            {
                int numberOfTokenReplacedForDirection = 0;
                eSignMarks[,] boardWithDirectionUpdated = null;

                performTokensReplacementForDirection(i_Token, direction, i_Row, i_Col, o_NewBoardStatus, out boardWithDirectionUpdated, out numberOfTokenReplacedForDirection);
                if (numberOfTokenReplacedForDirection > 0 && boardWithDirectionUpdated != null)
                {
                    o_NewBoardStatus            = boardWithDirectionUpdated;
                    o_NumberTokensThatReplaced += numberOfTokenReplacedForDirection;
                }
            }
        }
コード例 #6
0
ファイル: GameBoard.cs プロジェクト: yarin1006/Reversi
        private void performTokensReplacementForDirection(
            eSignMarks i_Symbol,
            eMoveDirection i_MoveDirection,
            int i_Row,
            int i_Col,
            eSignMarks[,] i_PreviousBoardStatus,
            out eSignMarks[,] o_NewBoardStatus,
            out int o_NumberOfTokenReplaced)
        {
            o_NewBoardStatus        = null;
            o_NumberOfTokenReplaced = 0;

            eSignMarks[,] boardStateWithUpdatedDirection = new eSignMarks[BoardSize, BoardSize];
            Array.Copy(i_PreviousBoardStatus, boardStateWithUpdatedDirection, i_PreviousBoardStatus.Length);
            boardStateWithUpdatedDirection[i_Row, i_Col] = i_Symbol;

            int        possibleNumberOfTokensReplaced = 0;
            bool       AriiveTOBorder;
            eSignMarks previousTokenValue = eSignMarks.Blank;
            int        row = i_Row;
            int        col = i_Col;

            do
            {
                advanceInMatrix(i_MoveDirection, ref row, ref col, out AriiveTOBorder);
                if (!AriiveTOBorder)
                {
                    previousTokenValue = boardStateWithUpdatedDirection[row, col];
                    boardStateWithUpdatedDirection[row, col] = i_Symbol;
                }
                ++possibleNumberOfTokensReplaced;
            }while (previousTokenValue != i_Symbol && previousTokenValue != eSignMarks.Blank && !AriiveTOBorder);

            if (!AriiveTOBorder && previousTokenValue != eSignMarks.Blank && possibleNumberOfTokensReplaced > 1)
            {
                o_NumberOfTokenReplaced = possibleNumberOfTokensReplaced;
                o_NewBoardStatus        = boardStateWithUpdatedDirection;
            }
        }
コード例 #7
0
 public ComputerVsPlayer(string i_Name, eSignMarks i_TokenMark)
     : base(i_Name, i_TokenMark)
 {
 }
コード例 #8
0
ファイル: Player.cs プロジェクト: yarin1006/Reversi
 /// <summary>
 ///   Methods
 /// </summary>
 public Player(string i_Name, eSignMarks i_TokenMark)
 {
     PlayerName      = i_Name;
     TokenMark       = i_TokenMark;
     TotalGamesScore = 0;
 }
コード例 #9
0
ファイル: HumanVsPlayer.cs プロジェクト: yarin1006/Reversi
 public HumanVsPlayer(string i_Name, eSignMarks i_TokenMark)
     : base(i_Name, i_TokenMark)
 {
 }