예제 #1
0
        public void MakeMove(GameDesk i_Desk)
        {
            Move move;

            refreshLegalMoves(i_Desk, false);
            if (m_LegalMoves.Count != 0)
            {
                move = m_LegalMoves[m_Rand.Next(0, m_LegalMoves.Count)];
                i_Desk.MakeMove(move.RowFrom, move.ColFrom, move.RowTo, move.ColTo, r_Symbol, r_SymbolKing, r_Position);
                if (i_Desk.CalcMoveDistance(move.RowFrom, move.ColFrom, move.RowTo, move.ColTo, r_Position) == 2)
                {
                    while (i_Desk.CheckIfMustKick(move.RowTo, move.ColTo, r_Position))
                    {
                        m_LastMove = move;
                        refreshLegalMoves(i_Desk, true);
                        if (m_LegalMoves.Count == 0)
                        {
                            break;
                        }

                        move = m_LegalMoves[m_Rand.Next(0, m_LegalMoves.Count)];
                        i_Desk.MakeMove(move.RowFrom, move.ColFrom, move.RowTo, move.ColTo, r_Symbol, r_SymbolKing, r_Position);
                    }
                }
            }
        }
예제 #2
0
        private void refreshLegalMoves(GameDesk i_Desk, bool i_IsAfterKick) // find all available moves on desk for computer
        {
            bool   isKickOption = false;
            bool   isMustKick   = false;
            string coordinates;

            m_LegalMoves.Clear();
            if (i_IsAfterKick)
            {
                isMustKick = i_Desk.CheckIfMustKick(m_LastMove.RowTo, m_LastMove.ColTo, r_Position);
                if (isMustKick)
                {
                    coordinates = i_Desk.GetKickOptions(m_LastMove.RowTo, m_LastMove.ColTo, r_Position);

                    for (int index = 0; index < coordinates.Length; index += 2)
                    {
                        m_LegalMoves.Add(new Move(m_LastMove.RowTo, m_LastMove.ColTo, int.Parse(coordinates[index].ToString()), int.Parse(coordinates[index + 1].ToString())));
                    }
                }
            }
            else
            {
                isKickOption = i_Desk.CheckForKickOption(r_Symbol, r_SymbolKing, r_Position); // player must kick some cell
                for (int i = 0; i < i_Desk.Size; i++)
                {
                    for (int j = 0; j < i_Desk.Size; j++)
                    {
                        if (i_Desk.Desk[i, j] == r_Symbol || i_Desk.Desk[i, j] == r_SymbolKing)
                        {
                            if (isKickOption && i_Desk.CheckIfCanKick(i, j, r_Position))
                            {
                                coordinates = i_Desk.GetKickOptions(i, j, r_Position);

                                for (int index = 0; index < coordinates.Length; index += 2)
                                {
                                    m_LegalMoves.Add(new Move(i, j, int.Parse(coordinates[index].ToString()), int.Parse(coordinates[index + 1].ToString())));
                                }
                            }
                            else if (!isKickOption)
                            {
                                if (i_Desk.CheckIfCanMove(i, j, i_Desk.Desk[i, j] == r_SymbolKing, r_Position))
                                {
                                    coordinates = i_Desk.GetMoveOptions(i, j, i_Desk.Desk[i, j] == r_SymbolKing, r_Position);
                                    for (int index = 0; index < coordinates.Length; index += 2)
                                    {
                                        m_LegalMoves.Add(new Move(i, j, int.Parse(coordinates[index].ToString()), int.Parse(coordinates[index + 1].ToString())));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        public DamkaController(int i_Size, string i_NamePlayer1, string i_NamePlayer2, bool i_TwoPlayersGame)
        {
            m_Desk     = new GameDesk(i_Size);
            m_DeskSize = i_Size;
            m_Player1  = new User(i_NamePlayer1, 1, eSymbols.Player1, eSymbols.Player1King, GameDesk.ePositionOnDesk.DOWN);
            if (i_TwoPlayersGame)
            {
                m_Player2  = new User(i_NamePlayer2, 2, eSymbols.Player2, eSymbols.Player2King, GameDesk.ePositionOnDesk.UP);
                m_GameMode = eGameMode.HUMAN;
            }
            else
            {
                m_Player2  = new ComputerDummy(i_NamePlayer2);
                m_GameMode = eGameMode.COMPUTER;
            }

            m_GameStatus      = eGameStatus.RUNNING;
            m_Last_move       = null;
            m_CurrentPlayer   = m_Player1;
            m_IsMustKickAgain = false;
            m_PointsPlayer1   = 0;
            m_PointsPlayer2   = 0;
        }