My Project
UML Lab
|
All program code files and PlantUML code are in the repository(https://github.com/b0re3b/projectchechkers)
This program implements a simple checkers game with an AI player using the Minimax algorithm. The game is developed using the SFML (Simple and Fast Multimedia Library) for graphical rendering. The main components of the program are the Board
, Piece
, Player
, Move
, MoveNode
, Menu
, and Game
classes.
The Board
class is responsible for managing the game state, including the positions of pieces, handling user input, drawing the board and pieces, and implementing the game logic such as move validation, highlighting possible moves, and checking for the endgame condition. It also contains methods for evaluating the board state and generating possible moves for the AI.
InitializeGame
: Sets up the initial positions of the pieces on the board.validarity
: Checks if a move is valid.inputdata
: Handles user input for selecting and moving pieces.highlight
: Highlights possible moves for a selected piece.numberofmoves
: Returns the number of possible moves for a player.endgame
: Checks if the game has ended.draw
: Draws the board and pieces on the window.evaluateBoard
: Evaluates the board state for the AI.MinMaxTree
: Generates the Minimax tree for the AI.BestMove
: Finds the best move for the AI using the Minimax algorithm.opponentPiece
: Checks if a piece belongs to the opponent.generateMoves
: Generates all possible moves for the current player.minimax
: Minimax algorithm implementation.ComputerMove
: Makes a move for the computer player.MousePosition
: Gets the index of a piece based on mouse position.makeMove
: Makes a move on the board.The Piece
class represents a single piece on the board. It includes attributes like isAlive
, isKing
, color
, x
, and y
to store the piece's state and position. The Draw
method renders the piece on the window.
The Player
class represents a player in the game. It has attributes for the player's color and type (human or computer).
The Move
class represents a move in the game, storing the start and end positions of a piece.
The MoveNode
class is used in the Minimax algorithm to represent nodes in the Minimax tree. Each node contains a move, a score, and a list of child nodes.
The Menu
class handles the user interface for choosing the player's color at the beginning of the game. It displays text options for "Red" and "Black" and returns the selected color.
The Game
class manages the main game loop, initializing the board and players, and running the game until it ends.
Menu
class displays a menu for the player to choose their color.Game
class runs the main game loop, which handles drawing the board, processing user input, and making moves.inputdata
method in the Board
class processes user input for selecting and moving pieces. It highlights possible moves and validates the selected move.ComputerMove
method in the Board
class generates the best move using the Minimax algorithm and makes the move.To build and run the program, ensure you have SFML installed and set up correctly. Use a build system like CMake to compile the code.
The program contains unit tests that cover part of the functionality, namely checking the validity of the move, algorithm and computer moves and input data
UML stands for Unified Modeling Language. It's a standardized general-purpose modeling language in the field of software engineering. UML provides a way to visualize a system's design through a variety of diagrams such as class diagrams, sequence diagrams, use case diagrams, and more.
This diagram illustrates the interaction flow between a human player, a computer player, and the game system in a checkers-like game. It outlines the sequence of actions and decisions taken by both players during gameplay. Each use case represents a specific action or event within the game, such as starting the game, choosing colors, selecting pieces, making moves, and checking for game over conditions. Overall, the diagram provides a structured overview of the game's main interactions and processes.
This diagram depicts the structure and interactions within a checkers-like game software system. It consists of several classes representing different components of the game, such as the game itself, the menu, the board, player, pieces, moves, and move nodes.The "Game" class manages the core gameplay loop and interactions between the players and the board. It contains references to the board, human player, computer player, and the SFML render window. The "Menu" class handles the menu interface for player color selection.The "Board" class represents the game board and contains the pieces. It provides functions for selecting and validating moves, updating the board, checking for game over conditions, generating moves, and more. The "Piece" class represents individual pieces on the board and provides functionality to draw them on the screen.The "Player" class defines players in the game, specifying their color and type (human or computer). The "Move" class represents a move in the game, storing starting and ending coordinates. The "MoveNode" class is used in the minimax algorithm for move evaluation.The diagram shows the relationships between these classes, such as how the game uses the menu and board, how the board contains pieces and uses moves, and how players make moves.
This diagram represents the components of a checkers game software system. It includes various modules such as the game application itself, menu, board, player, piece, move, and move node.
The "Game Application" artifact serves as the main application of the checkers game. It utilizes the "Menu" module for managing user interface interactions, the "Board" module for controlling the game board, and the "Player" module for managing player actions.
The "Board" module contains the game board and interacts with the "Piece" module, which represents individual pieces on the board. Additionally, the "Board" module utilizes the "Move" module for managing moves made during the game.
The "Player" module controls the actions of the players in the game and utilizes the "Move" module for making moves on the board.
Lastly, the "Move" module interacts with the "MoveNode" module, which is used for move evaluation and decision-making processes within the game.
Overall, this diagram provides an overview of the components and their interactions within the checkers game software system.
The diagram depicts the structural composition and interconnections among different components within a game software system. It outlines the relationships between key entities such as the Game, Board, HumanPlayer, ComputerPlayer, Piece, Menu, and RenderWindow. These entities interact and collaborate to facilitate the functionality and operation of the game application.
This diagram illustrates the internal structure of a game system, organized into a package named "Game." Within this package, there are several components: Game, Board, Players, Menu, and RenderWindow. The Board component contains a sub-component Square, which represents the grid of squares on the game board. The Players component further contains two sub-components: HumanPlayer and ComputerPlayer. The Game component interacts with the RenderWindow component for displaying the game interface.
This diagram depicts a software architecture where the "Game Application" artifact resides on the "User Machine" node. Within the "Game Application," there are several components: Game, Menu, Board, Player, Piece, Move, and MoveNode. The relationships between these components are shown with arrows indicating their interactions. For instance, Game uses Menu and Board, while Board contains Piece and uses Move. Similarly, Piece involves Move, and Player makes Move, and Move uses MoveNode.
This diagram illustrates the component structure of a game application. It's organized into different packages: "Game," "Components," and "Players."
The "Components" package includes classes such as Game, Board, Piece, Move, and MoveNode, representing various elements of the game logic.
The "Players" package contains the Player class and the PlayerType enumeration, distinguishing between human and computer players.
Outside the packages, there are two standalone classes: Menu and RenderWindow.
The arrows indicate dependencies and relationships between the components. For example, the Game component depends on both Components and Players, while Game.Components encompasses all the internal components. Additionally, the Game component uses Menu and interacts with the RenderWindow class.
It shows the sequence of interactions and message exchanges between different components or actors within the system during a specific scenario or use case. This includes how various elements of the system collaborate to achieve a particular functionality or behavior. The goal is to provide a clear understanding of the flow of control and data within the system, highlighting the order in which actions are performed and how they affect the system's state.
The activity diagram illustrates the sequential flow of actions within a game application, guiding from initialization to completion. It commences with the game initialization, proceeds through player interaction, and concludes upon game termination.
At the outset, the game initializes its components, displaying the menu for player interaction. Upon selection of a preferred color, the game enters the main loop, alternating between the human player's turn and the computer player's turn.
The diagram depicts the interaction flow in a checkers game. It begins with the human player choosing a color. The game initializes, and a loop starts, handling player turns and moves. The process repeats until the game ends. After each move, the results are displayed.
This diagram illustrates the states and transitions in a checkers game. It begins in the "Idle" state, waiting for players. When the game starts, it initializes and transitions to the "PlayerTurn" state. In this state, the human player takes their turn, validates their move, updates the board, and checks if the game is over. If not, it switches to the computer player's turn. The computer generates and executes its move, followed by updating the board and checking for game over. The process continues until the game ends, leading to the "GameOver" state.
Some changes have already been implemented here regarding the project in the first semester, but as I continue to work with this project, I plan to break the board class into simpler ones, make more unit tests and improve the operation of the program.