Ejemplo n.º 1
0
        /**
         * Play human taking action
         * @param a Action
         * @return Status flag
         */
        private Status Human(Taking a)
        {
            State s = m_gameTree.CurrentState();

            // human take action
            if (s == null)
            {
                return(Status.INVALIDACTION);
            }
            else
            {
                // first check if a taking action is possible at all
                if (s.TakingIsPossible(State.OppositeColor(a.Color())))
                {
                    // now check if a is a valid taking action
                    if (a.IsValid(s))
                    {
                        // play human player action a
                        m_gameTree.HumanPlayer(a);
                        if (VERBOSE)
                        {
                            Debug.WriteLine("Human has played\n\ttree size: " + m_gameTree.Size());
                        }

                        m_view.UpdateBoard(m_gameTree.CurrentState(), a, false);
                        if (s.Finished())
                        {
                            if (VERBOSE)
                            {
                                Debug.WriteLine("Human has won");
                            }
                            return(Status.FINISHED);
                        }
                        else
                        {
                            return(Status.OK);
                        }
                    }
                    else
                    {
                        // ActionPM part of a is valid, just the taking is invalid
                        State sCopy = s.Clone();

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

                        // redraw game board
                        return(Status.INVALIDACTION);
                    }
                }
                else
                {
                    m_view.UpdateBoard(m_gameTree.CurrentState(), a, false);
                    return(Status.OK);
                }
            }
        }
Ejemplo n.º 2
0
        /**
         * Take stone and update winner
         * @param a Action
         */
        public void Update(Taking a)
        {
            if (a == null)
            {
                throw new Exception("action is null");
            }

            byte pos   = a.TakePosition;
            var  color = a.TakeColor; // color of taken stone

            if (!IsValidTake(pos, color))
            {
                throw new Exception("invalid action");
            }

            m_board[pos] = IController.NONE;
            m_stonesOnBoard[color]--;

            if ((MovingPhase(color) || JumpingPhase(color)) && m_stonesOnBoard[color] < 3)
            {
                m_winner = a.Color();
            }
            CheckMove();
        }