Пример #1
0
        /**
         * Set player who opens the game.
         * called by parallel thread in a server game
         */
        public override void SetStarter(bool b)
        {
            if (b)
            {
                // computer starts
                if (VERBOSE)
                {
                    Debug.WriteLine("Computer starts");
                }
                m_humanColor  = IController.BLACK;
                m_humanStarts = false;
            }
            else
            {
                // human starts
                if (VERBOSE)
                {
                    Debug.WriteLine("Human starts");
                }
                m_humanColor  = IController.WHITE;
                m_humanStarts = true;
            }

            // refresh gui: must be called after beginning player have been chosen
            m_view.PrepareBoard();

            // create new game tree
            m_gameTree = new GameTree();
            if (b)
            {
                // computer will open the game
                m_gameTree.Create(TREEDEPTH, null);
                if (VERBOSE)
                {
                    Debug.WriteLine("\tgame tree created; tree size: " + m_gameTree.Size());
                }
            }
        }
Пример #2
0
        /**
         * Play human player action
         * @param a Action
         * @return status flag
         */
        private Status Human(ActionPM a)
        {
            State s = m_gameTree.CurrentState();

            // play human action
            if (s == null)
            {
                if (a is Placing)
                {
                    if (m_humanColor != IController.WHITE)
                    {
                        throw new Exception("wrong human player color");
                    }
                    m_gameTree.Create(TREEDEPTH, (Placing)a);
                    s = m_gameTree.CurrentState();
                    if (VERBOSE)
                    {
                        Debug.WriteLine("Human has played\n\ttree size: " + m_gameTree.Size());
                    }
                }
                else
                {
                    m_view.UpdateBoard(m_gameTree.CurrentState(), a, false);
                    return(Status.INVALIDACTION);
                }
            }
            else
            {
                // check if a is a valid human player action
                if (a.IsValid(s))
                {
                    var sCopy = s.Clone();

                    // update temporary state with user action
                    a.Update(sCopy);

                    // check if a mill has been closed
                    if (sCopy.InMill(a.EndPosition, a.Color()))
                    {
                        // action is not yet played, because it is part of a taking action
                        if (VERBOSE)
                        {
                            Debug.WriteLine("Human closed mill\n\ttree size: " + m_gameTree.Size());
                        }
                        // redraw game board
                        m_view.UpdateBoard(sCopy, a, false);
                        return(Status.CLOSEDMILL);
                    }
                    else
                    {
                        // play human player action a
                        m_gameTree.HumanPlayer(a);
                        if (VERBOSE)
                        {
                            Debug.WriteLine("Human has played\n\ttree size: " + m_gameTree.Size());
                        }
                    }
                }
                else
                {
                    if (VERBOSE)
                    {
                        Debug.WriteLine("Human played an invalid action");
                    }
                    m_view.UpdateBoard(m_gameTree.CurrentState(), a, false);
                    return(Status.INVALIDACTION);
                }
            }

            if (s.Finished())
            {
                if (VERBOSE)
                {
                    Debug.WriteLine("Human has won");
                }
                m_view.UpdateBoard(m_gameTree.CurrentState(), a, false);
                return(Status.FINISHED);
            }
            else
            {
                m_view.UpdateBoard(m_gameTree.CurrentState(), a, false);
                return(Status.OK);
            }
        }