private void MBoardOnOnBoardRectPressed(object sender, EventArgs eventArgs) { if (_selecterEllipse == null || !IsGameRunning) { return; } var rect = (Rectangle)sender; var color = GetColorIdex(_selectedEllipseColor); switch (GetState(color)) { case BoardState.Placing: if (_selecterEllipse != null) { _previousAction = new Placing(color, (int)rect.Tag); var status = _ctrl.Play(_previousAction); if (status == IController.Status.CLOSEDMILL) { ComputerIsPlaying = false; _take = true; Message = "You have a Mill take a stone"; } else { Compute(); } } break; case BoardState.Moving: case BoardState.Jumping: if (_selecterEllipse != null) { if (_selecterEllipse.Tag == null) { return; } _previousAction = new Moving(color, (int)_selecterEllipse.Tag, (int)rect.Tag); var status = _ctrl.Play(_previousAction); if (status == IController.Status.CLOSEDMILL) { ComputerIsPlaying = false; _take = true; Message = "You have a Mill take a stone"; } else { Compute(); } } break; default: throw new ArgumentOutOfRangeException(); } _selecterEllipse.Fill = new SolidColorBrush(_selectedEllipseColor); _selecterEllipse = null; }
/** * 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); } }