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

Checkers #40

Merged
merged 68 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
b1c3aeb
Initial cut
Wycott Jun 16, 2022
edab10f
Overhaul the way moves are made, remove some cruft from the engine, a…
Wycott Jun 17, 2022
e171168
prompt user on invalid input rather than default
ZacharyPatten Jun 18, 2022
757488c
implicit usings -> global usings
ZacharyPatten Jun 18, 2022
3ab4529
minor clean up
ZacharyPatten Jun 18, 2022
42b44a1
mor appropriate exception
ZacharyPatten Jun 18, 2022
33c05b9
game state loop clean up: handle each state in a seperate method
ZacharyPatten Jun 18, 2022
0b2168c
NewGuid for random selection is unnecessary
ZacharyPatten Jun 18, 2022
3a73f32
user confirmation > Thread.Sleep
ZacharyPatten Jun 18, 2022
b098a15
root readme +Checkers
ZacharyPatten Jun 19, 2022
2573823
slnf +Checkers
ZacharyPatten Jun 19, 2022
4ace7b9
Checkers Build Action
ZacharyPatten Jun 19, 2022
62002c7
Visual Studio Code Checkers launch
ZacharyPatten Jun 19, 2022
f82f271
Checkers readme
ZacharyPatten Jun 19, 2022
e3a82dd
always list the default enum value first with value 0
ZacharyPatten Jun 19, 2022
07db906
file names should match class names
ZacharyPatten Jun 19, 2022
57e559b
remove unnecessary using (the Thread.Sleep was previously removed)
ZacharyPatten Jun 19, 2022
a94140e
refactor coordinates (1..8->0..7) and position helper and move BoardH…
ZacharyPatten Jun 19, 2022
37436f5
moved DisplayHelper into Display
ZacharyPatten Jun 19, 2022
15b9abc
press key to continue clean up
ZacharyPatten Jun 19, 2022
fe4f45e
log file based on command line args rather than a const variable
ZacharyPatten Jun 19, 2022
9ea5e69
white space
ZacharyPatten Jun 19, 2022
1133813
moved input/output into Program.cs
ZacharyPatten Jun 21, 2022
9897b5c
moved position logic into Board.cs
ZacharyPatten Jun 21, 2022
2e30535
moved initial board layout into Board.cs
ZacharyPatten Jun 21, 2022
fbc72ab
removed InPlay from Piece
ZacharyPatten Jun 21, 2022
7b05b54
rename Color types and properties
ZacharyPatten Jun 21, 2022
60f53a2
rename GameState to ProgramState
ZacharyPatten Jun 21, 2022
d235f36
move Player initialization logic into Game.cs
ZacharyPatten Jun 21, 2022
65548ef
various clean up
ZacharyPatten Jun 21, 2022
03c294d
fix inverted y-axis
ZacharyPatten Jun 21, 2022
7cf9a87
removed "NotSet" PieceColor in favor of nullability
ZacharyPatten Jun 21, 2022
d044761
added human player count exception check on game constructor
ZacharyPatten Jun 21, 2022
d55cf1a
various clean up
ZacharyPatten Jun 21, 2022
5a63595
renamed Types -> Enums
ZacharyPatten Jun 21, 2022
7219478
removed logging (might add back in future)
ZacharyPatten Jun 21, 2022
7944add
various clean up
ZacharyPatten Jun 21, 2022
b29482e
remove DeriveToPosition (you can just multiply by 2)
ZacharyPatten Jun 21, 2022
d02499f
removed MoveCount because it wasn't calculating correctly
ZacharyPatten Jun 21, 2022
47af07b
clean up
ZacharyPatten Jun 21, 2022
857b2df
remove PlayerAction (missed when removed logging)
ZacharyPatten Jun 21, 2022
f0bf9e0
removed MoveType
ZacharyPatten Jun 21, 2022
7c9e2ff
removed MoveOutcome.Unkown
ZacharyPatten Jun 21, 2022
83f5c7f
rename NextRound to NextTurn
ZacharyPatten Jun 21, 2022
99590bb
moved Aggressor from Piece to Board (there can only be one aggressor …
ZacharyPatten Jun 21, 2022
b4675fc
fix aggressor reset bug
ZacharyPatten Jun 21, 2022
8eb2db8
removed ProgramState
ZacharyPatten Jun 21, 2022
567db32
moved VectorHelper into Engine
ZacharyPatten Jun 21, 2022
c08b7db
renamed Piece XPosition & YPosition to X & Y
ZacharyPatten Jun 21, 2022
9ff992f
adjustments to output
ZacharyPatten Jun 21, 2022
cf4b4bd
removed Direction; enums are great, but if it is only used inside one…
ZacharyPatten Jun 21, 2022
28c4979
removed PlayerControl; enums are great, but if there are only 2 value…
ZacharyPatten Jun 21, 2022
aa1ddf6
moved enums out of Enums folder (if there are only two types in there…
ZacharyPatten Jun 21, 2022
c883903
global using static Black/White
ZacharyPatten Jun 21, 2022
6757b2a
removed GetPointDistance; the distance between points is only used fo…
ZacharyPatten Jun 22, 2022
1e70415
"side" -> "color"
ZacharyPatten Jun 22, 2022
6515f2c
'.' -> '·' (period to middle dot for vacant tiles)
ZacharyPatten Jun 22, 2022
e54af78
clean up Program.cs
ZacharyPatten Jun 22, 2022
36175e4
added Visualized for Aggressor
ZacharyPatten Jun 22, 2022
b79c2ed
reimplementations
ZacharyPatten Jun 22, 2022
b5c477a
menu input adjustment
ZacharyPatten Jun 22, 2022
ace71b7
intro screen and readme update
ZacharyPatten Jun 23, 2022
04e7266
moved Checkers to Weight of 4 in root README.md
ZacharyPatten Jun 23, 2022
6fa4570
Checkers blazor port
ZacharyPatten Jun 23, 2022
9c14b10
added exception text that matches condition check
ZacharyPatten Jun 23, 2022
029f097
unnecessary qualification
ZacharyPatten Jun 23, 2022
880198f
clean up from feedback on pull request
ZacharyPatten Jun 23, 2022
a7f2c78
ValidateMove -> ValidateDiagonalMove
ZacharyPatten Jun 23, 2022
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
24 changes: 24 additions & 0 deletions .github/workflows/Checkers Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Checkers Build
on:
push:
paths:
- 'Projects/Checkers/**'
branches:
- main
pull_request:
paths:
- 'Projects/Checkers/**'
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: dotnet build
run: dotnet build "Projects\Checkers\Checkers.csproj" --configuration Release
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@
"console": "externalTerminal",
"stopAtEntry": false,
},
{
"name": "Checkers",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build Checkers",
"program": "${workspaceFolder}/Projects/Checkers/bin/Debug/Checkers.dll",
"cwd": "${workspaceFolder}/Projects/Checkers/bin/Debug",
"console": "externalTerminal",
"stopAtEntry": false,
},
{
"name": "Blackjack",
"type": "coreclr",
Expand Down
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
"version": "2.0.0",
"tasks":
[
{
"label": "Build Checkers",
"command": "dotnet",
"type": "process",
"args":
[
"build",
"${workspaceFolder}/Projects/Checkers/Checkers.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary",
],
"problemMatcher": "$msCompile",
},
{
"label": "Build Duck Hunt",
"command": "dotnet",
Expand Down
16 changes: 16 additions & 0 deletions Projects/Checkers/Board.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Checkers;

public class Board
{
public List<Piece> Pieces { get; set; }

public Board()
{
Pieces = BoardHelper.GetStartingPosition();
}

public Board(List<Piece> startingPosition)
{
Pieces = startingPosition;
}
}
8 changes: 8 additions & 0 deletions Projects/Checkers/Checkers.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
ZacharyPatten marked this conversation as resolved.
Show resolved Hide resolved
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
56 changes: 56 additions & 0 deletions Projects/Checkers/Data/KnowledgeBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace Checkers.Data;

/// <summary>
/// Stores the starting position and any custom permutation for testing
/// </summary>
public static class KnowledgeBase
{
public static List<Piece> GetStartingPosition()
{
var retVal = new List<Piece>
{
new() { InitialPosition ="A3", Side = PieceColour.Black},
new() { InitialPosition ="A1", Side = PieceColour.Black},
new() { InitialPosition ="B2", Side = PieceColour.Black},
new() { InitialPosition ="C3", Side = PieceColour.Black},
new() { InitialPosition ="C1", Side = PieceColour.Black},
new() { InitialPosition ="D2", Side = PieceColour.Black},
new() { InitialPosition ="E3", Side = PieceColour.Black},
new() { InitialPosition ="E1", Side = PieceColour.Black},
new() { InitialPosition ="F2", Side = PieceColour.Black},
new() { InitialPosition ="G3", Side = PieceColour.Black},
new() { InitialPosition ="G1", Side = PieceColour.Black},
new() { InitialPosition ="H2", Side = PieceColour.Black},
new() { InitialPosition ="A7",Side = PieceColour.White},
new() { InitialPosition ="B8",Side = PieceColour.White},
new() { InitialPosition ="B6",Side = PieceColour.White},
new() { InitialPosition ="C7",Side = PieceColour.White},
new() { InitialPosition ="D8",Side = PieceColour.White},
new() { InitialPosition ="D6",Side = PieceColour.White},
new() { InitialPosition ="E7",Side = PieceColour.White},
new() { InitialPosition ="F8",Side = PieceColour.White},
new() { InitialPosition ="F6",Side = PieceColour.White},
new() { InitialPosition ="G7",Side = PieceColour.White},
new() { InitialPosition ="H8",Side = PieceColour.White},
new() { InitialPosition ="H6",Side = PieceColour.White}
};

return retVal;
}

public static List<Piece> GetLimitedStartingPosition()
{
var retVal = new List<Piece>
{
new () { InitialPosition ="H2", Side = PieceColour.Black},
new () { InitialPosition ="A1", Side = PieceColour.Black},
new () { InitialPosition ="G3", Side = PieceColour.White},
new() { InitialPosition = "E5", Side = PieceColour.White}
};

return retVal;
}


}

100 changes: 100 additions & 0 deletions Projects/Checkers/Display.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Drawing;

namespace Checkers;

public static class Display
{
private const string BlackPiece = "○";
private const string BlackKing = "☺";
private const string WhitePiece = "◙";
private const string WhiteKing = "☻";
ZacharyPatten marked this conversation as resolved.
Show resolved Hide resolved

public static void DisplayBoard(Board currentBoard)
{
PrintBoard();
PrintPieces(currentBoard);
Console.CursorVisible = false;
}

public static void DisplayStats(int whitesTaken, int blacksTaken)
{
Console.SetCursorPosition(22, 6);
Console.WriteLine(" Taken:");
Console.SetCursorPosition(22, 7);
Console.WriteLine($"{whitesTaken.ToString(),2} x {WhitePiece}");
Console.SetCursorPosition(22, 8);
Console.WriteLine($"{blacksTaken.ToString(),2} x {BlackPiece}");
}

public static void DisplayCurrentPlayer(PieceColour currentSide)
{
Console.SetCursorPosition(0, 11);
Console.WriteLine($"{currentSide} to play");
}

public static void DisplayWinner(PieceColour winningSide)
{
Console.SetCursorPosition(0, 11);
Console.WriteLine($"*** {winningSide} wins ***");
}

private static void PrintPieces(Board currentBoard)
{
foreach (var piece in currentBoard.Pieces.Where(x => x.InPlay))
{
var screenPosition =
DisplayHelper.GetScreenPositionFromBoardPosition(new Point(piece.XPosition, piece.YPosition));
var displayPiece = GetDisplayPiece(piece);
Console.SetCursorPosition(screenPosition.X, screenPosition.Y);
Console.Write(displayPiece);
}
}

private static string GetDisplayPiece(Piece currentPiece)
{
string retVal;

if (currentPiece.Side == PieceColour.Black)
{
retVal = currentPiece.Promoted ? BlackKing : BlackPiece;
}
else
{
retVal = currentPiece.Promoted ? WhiteKing : WhitePiece;
}

return retVal;
}

private static void PrintBoard()
{
Console.Clear();
var emptyBoard = GetBlankBoard();

foreach (var rank in emptyBoard)
{
Console.WriteLine(rank);
}
}

private static List<string> GetBlankBoard()
{
var retVal = new List<string>
{
$" ╔═══════════════════╗",
$"8║ . . . . . . . . ║ {BlackPiece} = Black",
$"7║ . . . . . . . . ║ {BlackKing} = Black King",
$"6║ . . . . . . . . ║ {WhitePiece} = White",
$"5║ . . . . . . . . ║ {WhiteKing} = White King",
$"4║ . . . . . . . . ║",
$"3║ . . . . . . . . ║",
$"2║ . . . . . . . . ║",
$"1║ . . . . . . . . ║",
$" ╚═══════════════════╝",
$" A B C D E F G H"
};

return retVal;
}
}

Loading