/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); IsMouseVisible = true; // Create and load space objects int xPos = DrawingConstants.X_BOARD_BUFFER; // Add space size added to account for blue arrow int yPos = DrawingConstants.Y_BOARD_BUFFER + DrawingConstants.SPACE_SIZE; for (int col = 0; col < NUM_COLUMNS; col++) { _boardColumns[col] = new BoardColumn( xPos, yPos, _imageDict[ImageNames.COLUMN_HOLDER], _imageDict[ImageNames.HIGHLIGHTED_COLUMN_HOLDER], _imageDict[ImageNames.BLUE_ARROW]); // Move to next column. xPos += DrawingConstants.SPACE_SIZE; } CurrentMenu = MenuState.Start; _winner = DiscColor.None; _startMenu = new StartMenu(_consolas24); _playAgainMenu = new PlayAgainMenu(_consolas24, GraphicsDevice); ResetGame(); }
private void OnPlayerMoveFinished(int rowIndex, int columnIndex, DiscColor color) { if (!this.Game.IsStopped) { MoveDelegate refreshControl = new MoveDelegate(this.RefreshControl); this.Invoke(refreshControl, rowIndex, columnIndex, color); } }
/// <summary> /// Updates the player and bot disc colors and the /// menu state to reflect that the player has chosen /// which color they would like to play. /// </summary> /// <param name="playerChoice"></param> void SetGameColors(DiscColor playerChoice) { PlayerTurn = playerChoice; BotTurn = ChangeTurnColor(playerChoice); Bot = new ConnectAI(BotTurn); CurrentMenu = MenuState.None; }
public BoardFieldControl(BoardControl boardControl, int rowIndex, int columnIndex, DiscColor currentColor) { this.mBoardControl = boardControl; this.mRowIndex = rowIndex; this.mColumnIndex = columnIndex; this.mCurrentColor = currentColor; this.InitializeComponent(); this.Width = SIZE; this.Height = SIZE; }
public static DiscColor ChangeTurnColor(DiscColor color) { if (color != DiscColor.Red && color != DiscColor.Black) { throw new ArgumentException("Must pass in a valid disc color.", nameof(color)); } return(color == DiscColor.Red ? DiscColor.Black : DiscColor.Red); }
private void RefreshControl(int rowIndex, int columnIndex, DiscColor color) { this.RefreshFieldsColors(); this.ctrlPlayer1.RefreshInfo(); this.ctrlPlayer2.RefreshInfo(); Player player = (this.Game.Player2.Color == color) ? this.Game.Player2 : this.Game.Player1; this.RefreshLastMoveInfo(player, rowIndex, columnIndex); this.RefreshCurrentMoveInfo(); this.StartTimer(); }
protected void VictoryConfirmed(DiscColor winner) { if (winner != DiscColor.None) { ShowPlayAgainMenu(winner); } else { if (BitBoardHelpers.GetOpenColumns(GetBitBoard()).Count == 0) { ShowPlayAgainDrawnMenu(); } } }
public decimal EndGameScore(DiscColor disc, int depth) { // what to return here!?!? if (disc == DiscColor.None) { throw new ArgumentException("The disc cannot be None", nameof(disc)); } if (disc == DiscColor.Black) { return(1000000.0m); } return(-1000000.0m); }
/// <summary> /// Sets the spaces at rowIndex in the column to be disc. /// </summary> /// <param name="disc"></param> public void SetSpace(DiscColor disc) { // Fill the first available space with the given disc. for (int t = 0; t < LogicalBoardHelpers.NUM_ROWS; t++) { if (columnSpaces[t].Disc == 0) { columnSpaces[t].Disc = disc; // Determine if column is full or still movable. if (t == LogicalBoardHelpers.NUM_ROWS - 1) { IsMovable = false; } return; } } }
/// <summary> /// Draws the play again menu to the screen. /// </summary> public void Draw( SpriteBatch sb, Dictionary <string, Texture2D> images, DiscColor winner, bool gameDrawn = false) { var menuText = gameDrawn ? "Game drawn! Play again?" : $"{winner} has won! Play again?"; sb.DrawString( _font, menuText, new Vector2(10, 10), Color.Black); sb.Draw( _buttonBackgroundTexture, _yesPosition, Color.White); sb.DrawString( _font, "Yes", new Vector2( TOP_BUFFER, 60), Color.Black); sb.Draw( _buttonBackgroundTexture, _noPosition, Color.White); sb.DrawString( _font, "No", new Vector2( TOP_BUFFER + BUTTON_WIDTH + 10, 60), Color.Black); }
// Use this for initialization void Start() { Thrower = hand.GetComponent <ThrowSpeed>(); disc_color = this.GetComponent <DiscColor>(); instructions = this.GetComponentInChildren <DiscInstructions>(); m_release_delay = release_delay; home = false; disc_start = GetComponents <AudioSource>()[0]; disc_idle = GetComponents <AudioSource>()[1]; disc_fly = GetComponents <AudioSource>()[2]; disc_throw = GetComponents <AudioSource>()[3]; disc_bounce = GetComponents <AudioSource>()[4]; foreach (AudioSource sound in GetComponents <AudioSource>()) { sound.pitch = 1 + pitch_modifier; } instructions.SetInstructionText(1); }
protected void ShowPlayAgainMenu(DiscColor winner) { _winner = winner; CurrentMenu = MenuState.PlayAgain; }
public override string ToString() { return($"Color={DiscColor.ToString()}"); }
public void Flip() { DiscColor = DiscColor.GetOpposite(); }
/// <summary> /// Constructor. /// </summary> /// <param name="color">Color for AI to play.</param> public ConnectAI(DiscColor color) { AiColor = color; OpponentColor = ChangeTurnColor(AiColor); }
private (decimal BoardScore, int Column) MinValue( BitBoard board, int depth, decimal alpha, decimal beta, NodeCounter nodeCounter, DiscColor movingColor) { nodeCounter.Increment(); var openColumns = GetOpenColumns(in board); // TODO I think these columns are safe but not certain // I didn't see any problems with this during some test games, may require more vetting though // Drawn game if (openColumns.Count == 0) { return(0.0m, -1); } if (depth == 0 || CheckVictory(in board) != DiscColor.None) { return(EvaluateBoardState(in board, movingColor), -1); } // Win and return immediately if possible var winningMove = FindKillerMove(in board, movingColor); if (winningMove.HasWinner && winningMove.Winner == movingColor) { var winningBoard = BitBoardMove(in board, winningMove.Column, movingColor); var winningScore = EvaluateBoardState(in winningBoard, movingColor); return(winningScore, winningMove.Column); } // Stop the opponent from winning if possible var oppWinningMove = FindKillerMove(in board, OpponentColor); if (oppWinningMove.HasWinner) { var stopWinningBoard = BitBoardMove(in board, oppWinningMove.Column, AiColor); var stopWinningScore = EvaluateBoardState(in stopWinningBoard, movingColor); return(stopWinningScore, oppWinningMove.Column); } decimal minimumMoveValue = decimal.MaxValue; int movedColumn = -1; foreach (int openMove in openColumns) { var newState = BitBoardMove(in board, openMove, movingColor); var childMaxValue = MaxValue(newState, depth - 1, alpha, beta, nodeCounter, ChangeTurnColor(movingColor)).BoardScore; if (childMaxValue < minimumMoveValue) { minimumMoveValue = childMaxValue; movedColumn = openMove; } if (minimumMoveValue <= alpha) { return(minimumMoveValue, openMove); } beta = Math.Min(beta, minimumMoveValue); } return(minimumMoveValue, movedColumn); }
public void Reset() { Disc = DiscColor.None; discDrawRect.Y = TOP_BUFFER + SPACE_SIZE; }
public Move(Position position, DiscColor disc) { Position = position; Disc = disc; }
public Move(int x, int y, DiscColor color) : this(new Position(x, y), color) { }
public KillerMove(int column, DiscColor disc) { Column = column; Winner = disc; }