Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation to some classes and methods. #497

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

namespace ChessChallenge.Application
{
/// <summary>
/// Main orchestrator class for the appplication. Contains the handles for when buttons are
/// pushed and triggers the UI drawing methods accordingly.
/// Maintains the application's state. The app's state includes things such as:
/// Aggregated game stats, current running game flag, current game's ID, current game's player types, etc.
/// </summary>
public class ChallengeController
{
public enum PlayerType
Expand Down Expand Up @@ -159,8 +165,10 @@ Move GetBotMove()
return Move.NullMove;
}



/// <summary>
/// If next player to move is human it enables the HumanPlayer's update() loop.
/// If next player to move is a bot then it gets the next bot move, updates the bot's clock and attempts to play it.
/// </summary>
void NotifyTurnToMove()
{
//playerToMove.NotifyTurnToMove(board);
Expand Down Expand Up @@ -256,9 +264,12 @@ void PlayMove(Move move)
bool animate = PlayerToMove.IsBot;
lastMoveMadeTime = (float)Raylib.GetTime();

// Paint/make move on the board
board.MakeMove(move, false);
boardUI.UpdatePosition(board, move, animate);

// Update the game state and notify the opponent that its their turn.
// End game if applicable.
GameResult result = Arbiter.GetGameState(board);
if (result == GameResult.InProgress)
{
Expand Down
6 changes: 6 additions & 0 deletions Chess-Challenge/src/Framework/Application/Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

namespace ChessChallenge.Application
{
/// <summary>
/// Contains the app's entry point and UI update loop.
/// This project uses the <see href="https://www.raylib.com/">Raylib</see> game engine.
/// Familiarize yourself with it before making any changes to the code.
/// </summary>
static class Program
{
const bool hideRaylibLogs = true;
Expand All @@ -31,6 +36,7 @@ public static void Main()

ChallengeController controller = new();

// The app's main update loop.
while (!Raylib.WindowShouldClose())
{
Raylib.BeginDrawing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace ChessChallenge.Application
{
/// <summary>
/// Contains state and methods necessary to control a human player in the framework.
/// </summary>
public class HumanPlayer
{
public event System.Action<Move>? MoveChosen;
Expand Down Expand Up @@ -84,6 +87,11 @@ void CancelDrag()
boardUI.ResetSquareColours(true);
}

/// <summary>
/// First checks if the chosen move is valid. If it is then the move is played.
/// </summary>
/// <param name="startSquare"></param>
/// <param name="targetSquare"></param>
void TryMakeMove(int startSquare, int targetSquare)
{
bool isLegal = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ namespace ChessChallenge.Chess
using System;
using static PrecomputedMoveData;

/// <summary>
/// Keeps the state of the current game (piece location, in-check flag, etc) and uses it to generate a collection of valid moves
/// for the current position.
/// </summary>
public class MoveGenerator
{
public const int MaxMoves = 218;
Expand Down Expand Up @@ -46,6 +50,8 @@ public enum PromotionMode { All, QueenOnly, QueenAndKnight }
// Otherwise it will have 1s everywhere.
ulong moveTypeMask;

// Generates list of legal moves in current position.
// Quiet moves (non captures) can optionally be excluded. This is used in quiescence search.
public System.Span<Move> GenerateMoves(Board board, bool includeQuietMoves = true)
{
System.Span<Move> moves = new Move[MaxMoves];
Expand Down
4 changes: 4 additions & 0 deletions Chess-Challenge/src/Framework/Chess/Result/Arbiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
{
using System.Linq;

/// <summary>
/// Contains methods to determine the status of a game (Draw, Win, etc) based on an instance of
/// the <see cref="Board"/> class.
/// </summary>
public static class Arbiter
{
public static bool IsDrawResult(GameResult result)
Expand Down
8 changes: 8 additions & 0 deletions Chess-Challenge/src/My Bot/MyBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

public class MyBot : IChessBot
{
/// <summary>
/// This method is called automatically by the framework whenever it's this bot's turn to move.
/// Illegal moves will be rejected by the framework.
/// Use the methods in <see cref="Board"/> such as GetLegalMoves() to help in making a decision for the bot's next move.
/// </summary>
/// <param name="board">The current board's status.</param>
/// <param name="timer">This bot's timer.</param>
/// <returns></returns>
public Move Think(Board board, Timer timer)
{
Move[] moves = board.GetLegalMoves();
Expand Down