void OnMoveMade(ExecuteMoveOperation operation) { if (this.MoveMade != null) { MoveMadeEventArgs args = new MoveMadeEventArgs(operation.Player, operation.Move); this.MoveMade(this, args); } }
/// <summary> /// Takes user interface input in the form of a mouse pointer location and the containing /// 3D viewport and attempts to "select" the piece that exists at that location. If a piece is /// found, the appropriate game operation is performed, such as highlighting a valid source, or /// executing a move. /// </summary> /// <param name="location"></param> /// <param name="viewport"></param> public void SelectPiece(Point location, Viewport3D viewport) { if (this.GameOver || this.showingOnlyPlacedPieces) { return; } ModelVisual3D hitTestResult = GameBoardController.GetHitTestResult(viewport, location); GamePieceVisual targetPiece = GameBoardController.ConvertHitTestResultToGamePieceVisual(hitTestResult); if (this.currentShowValidMoveOperation != null) { if (targetPiece != null && this.currentShowValidMoveOperation.ValidDestinationPieces.Contains(targetPiece)) { //execute move ExecuteMoveOperation operation = new ExecuteMoveOperation(this, this.currentShowValidMoveOperation.SourcePiece, targetPiece); this.currentShowValidMoveOperation.Hide(); this.currentShowValidMoveOperation = null; operation.Execute(); this.moveOperations.Add(operation); this.BuildBoardFromMoveHistory(); this.OnMoveMade(operation); this.CheckForEngineMove(); this.isDirty = true; } } else { if (targetPiece != null) { if (targetPiece.IsValidSource) { this.currentShowValidMoveOperation = new ShowValidMoveOperation(this, targetPiece); this.currentShowValidMoveOperation.Show(); } } } }
/// <summary> /// Automates an AI engine move if a plugin is used for the current player. /// </summary> void CheckForEngineMove() { Move move = null; if (this.board.Current == Players.X && this.PlayerX != null) { move = this.PlayerX.GenerateMove(board); } else if (this.board.Current == Players.O && this.PlayerO != null) { move = this.PlayerO.GenerateMove(this.board); } if (move != null) { ExecuteMoveOperation operation = new ExecuteMoveOperation(this, move); operation.Execute(); moveOperations.Add(operation); this.BuildBoardFromMoveHistory(); this.OnMoveMade(operation); this.isDirty = true; } }