From c4b21c41f422b1a3aae5b794365cc2dfb88942f0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 26 Feb 2019 15:24:49 -0600 Subject: [PATCH 01/19] almost done with checkers --- CheckersCheckpoint/.vscode/launch.json | 26 ++++ CheckersCheckpoint/.vscode/tasks.json | 15 +++ CheckersCheckpoint/Board.cs | 118 +++++++++++++++++++ CheckersCheckpoint/Checker.cs | 50 ++++++++ CheckersCheckpoint/CheckersCheckpoint.csproj | 8 ++ CheckersCheckpoint/Game.cs | 71 +++++++++++ CheckersCheckpoint/Program.cs | 14 +++ 7 files changed, 302 insertions(+) create mode 100644 CheckersCheckpoint/.vscode/launch.json create mode 100644 CheckersCheckpoint/.vscode/tasks.json create mode 100644 CheckersCheckpoint/Board.cs create mode 100644 CheckersCheckpoint/Checker.cs create mode 100644 CheckersCheckpoint/CheckersCheckpoint.csproj create mode 100644 CheckersCheckpoint/Game.cs create mode 100644 CheckersCheckpoint/Program.cs diff --git a/CheckersCheckpoint/.vscode/launch.json b/CheckersCheckpoint/.vscode/launch.json new file mode 100644 index 00000000..0e2310de --- /dev/null +++ b/CheckersCheckpoint/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/CheckersCheckpoint.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/CheckersCheckpoint/.vscode/tasks.json b/CheckersCheckpoint/.vscode/tasks.json new file mode 100644 index 00000000..c894cb0c --- /dev/null +++ b/CheckersCheckpoint/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/CheckersCheckpoint.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/CheckersCheckpoint/Board.cs b/CheckersCheckpoint/Board.cs new file mode 100644 index 00000000..c5007172 --- /dev/null +++ b/CheckersCheckpoint/Board.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CheckersCheckpoint +{ + public class Board + { + public string[][] grid; + public List checkers; + + public Board() + { + this.Checkers = new List(); + this.CreateBoard(); + return; + } + public string[][] Grid + { + get; + set; + } + public List Checkers + { + get; + set; + } + + + public void CreateBoard() + { + this.Grid = new string[][] + { + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + }; + return; + } + + + public void GenerateCheckers() + { + int[][] whitePositions = new int[][] + { + new int[] { 0, 1 }, new int[] { 0, 3 }, new int[] { 0, 5 }, new int[] { 0, 7 }, + new int[] { 1, 0 }, new int[] { 1, 2 }, new int[] { 1, 4 }, new int[] { 1, 6 }, + new int[] { 2, 1 }, new int [] { 2, 3 }, new int[] { 2, 5 }, new int[] { 2, 7} + }; + + int[][] blackPositions = new int[][] + { + new int[] { 5, 0 }, new int[] { 5, 2 }, new int[] { 5, 4 }, new int[] { 5, 6 }, + new int[] { 6, 1 }, new int[] { 6, 3 }, new int[] { 6, 5 }, new int[] { 6, 7 }, + new int[] { 7, 0 }, new int[] { 7, 2 }, new int [] { 7, 4 }, new int[] { 7, 6 } + }; + + for (int i = 0; i < 12; i++) + + { + Checker white = new Checker("white", whitePositions[i]); + Checker black = new Checker("black", blackPositions[i]); + Checkers.Add(white); + Checkers.Add(black); + } + return; + } + + + + public void PlaceCheckers() + { + foreach (var checker in Checkers) + { + // Console.WriteLine(checker.Position[0] + " " + checker.Position[1]); + this.Grid[checker.Position[0]][checker.Position[1]] = checker.Symbol; + } + return; + } + + + public void DrawBoard() + { + CreateBoard(); + PlaceCheckers(); + Console.WriteLine(" 0 1 2 3 4 5 6 7 "); + for (int i = 0; i < 8; i++) + { + Console.WriteLine(i + " " + String.Join(" ", this.Grid[i])); + } + return; + } + + + public Checker SelectChecker(int row, int column) + { + return Checkers.Find(x => x.Position.SequenceEqual(new List { row, column })); + } + + + public void RemoveChecker(Checker checker) + { + Checkers.Remove(checker); + return; + } + + + public bool CheckForWin() + { + return Checkers.All(x => x.Color == "white") || !Checkers.Exists(x => x.Color == "white"); + } + } +} \ No newline at end of file diff --git a/CheckersCheckpoint/Checker.cs b/CheckersCheckpoint/Checker.cs new file mode 100644 index 00000000..e77bdba1 --- /dev/null +++ b/CheckersCheckpoint/Checker.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CheckersCheckpoint +{ + public class Checker + { + public string symbol; + public int[] position; + public string color; + + + public Checker(string color, int[] position) + { + int circleId; + + if (color == "white") + { + circleId = int.Parse(" 25CE", System.Globalization.NumberStyles.HexNumber); + Color = "white"; + } + else + { + circleId = int.Parse(" 25C9", System.Globalization.NumberStyles.HexNumber); + Color = "black"; + } + this.Symbol = char.ConvertFromUtf32(circleId); + this.Position = position; + } + + public string Symbol + { + get; + set; + } + + public int[] Position + { + get; + set; + } + + public string Color + { + get; + set; + } + } +} \ No newline at end of file diff --git a/CheckersCheckpoint/CheckersCheckpoint.csproj b/CheckersCheckpoint/CheckersCheckpoint.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/CheckersCheckpoint/CheckersCheckpoint.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/CheckersCheckpoint/Game.cs b/CheckersCheckpoint/Game.cs new file mode 100644 index 00000000..27da0253 --- /dev/null +++ b/CheckersCheckpoint/Game.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CheckersCheckpoint +{ + public class Game + { + public Game() + { + Board board = new Board(); + board.GenerateCheckers(); + board.DrawBoard(); + + Console.WriteLine("\nIf you want to move a checker one space diagonally forward, enter 'move'."); + Console.WriteLine("\nIf a jump is available for one of your checker, you must enter 'jump'."); + + string choice = Console.ReadLine(); + + do + { + switch (choice) + { + case "move": + + Console.WriteLine("Enter checker Row to move:"); + int row = int.Parse(Console.ReadLine()); + Console.WriteLine("Enter checker Column:"); + int column = int.Parse(Console.ReadLine()); + + if (board.SelectChecker(row, column) != null) + { + Checker checker = board.SelectChecker(row, column); + Console.WriteLine("Move to which Row: "); + int newRow = int.Parse(Console.ReadLine()); + Console.WriteLine("Move to which Column: "); + int newColumn = int.Parse(Console.ReadLine()); + checker.Position = new int[] { newRow, newColumn }; + board.DrawBoard(); + } + else + { + Console.WriteLine("Invalid input"); + Console.WriteLine("Enter a valid checker Row:"); + row = int.Parse(Console.ReadLine()); + Console.WriteLine("Enter a valid checker Column:"); + column = int.Parse(Console.ReadLine()); + } + break; + + case "jump": + + Console.WriteLine("Select checker Row to remove:"); + int removeRow = int.Parse(Console.ReadLine()); + Console.WriteLine("Select checker Column to remove:"); + int removeColumn = int.Parse(Console.ReadLine()); + Checker changeChecker = board.SelectChecker(removeRow, removeColumn); + board.RemoveChecker(changeChecker); + board.DrawBoard(); + break; + + default: + + Console.WriteLine("Invalid input."); + break; + } + } + while (board.CheckForWin() != true); + } + } +} \ No newline at end of file diff --git a/CheckersCheckpoint/Program.cs b/CheckersCheckpoint/Program.cs new file mode 100644 index 00000000..f06cd63f --- /dev/null +++ b/CheckersCheckpoint/Program.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CheckersCheckpoint +{ + public class Program + { + public static void Main(string[] args) + { + new Game(); + } + } +} \ No newline at end of file From 8091add5028fd4c6dd14e1849e9179e2766ef391 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 26 Feb 2019 15:25:07 -0600 Subject: [PATCH 02/19] almost done with checkers --- CheckersCheckpoint/bash.exe.stackdump | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 CheckersCheckpoint/bash.exe.stackdump diff --git a/CheckersCheckpoint/bash.exe.stackdump b/CheckersCheckpoint/bash.exe.stackdump new file mode 100644 index 00000000..4bc86685 --- /dev/null +++ b/CheckersCheckpoint/bash.exe.stackdump @@ -0,0 +1,16 @@ +Stack trace: +Frame Function Args +00180328AF0 0018006021E (00180247D00, 001802340B9, 00000000058, 000FFFFB740) +00180328AF0 00180048859 (00180236765, 00100000000, 00000000000, 00000000001) +00180328AF0 00180048892 (00000000000, 00000000000, 00000000058, 00180328950) +00180328AF0 0018006C179 (0000000000A, 00000000000, 0000000000A, 00000000000) +00180328AF0 0018006C342 (00000000003, 00000000000, 00180044EEF, 000FFFFCB30) +00000000000 0018006D3A8 (0000000000D, 000FFFFC920, 001800E4CF6, 000FFFFC920) +00000000000 00180058816 (000FFFF0000, 00000000000, 00000000000, 006FFFFFFFF) +00000000000 001800590A9 (000FFFFCAF0, 00600040000, 00000000000, 000FFFFCB80) +00180325CF8 001800595BA (001800C0322, 00000000000, 00000000000, 00000000000) +000FFFFCCD0 00180059937 (000FFFFCDF0, 000FFFFCCD0, FFFFFFFFFFFFFFD1, 00000000000) +000FFFFCCD0 00180048FE1 (00000000000, 00000000000, 00000000000, 00000000000) +00000000000 00180047963 (00000000000, 00000000000, 00000000000, 00000000000) +000FFFFFFF0 00180047A14 (00000000000, 00000000000, 00000000000, 00000000000) +End of stack trace From 9dec5fac3b522276be6440dbbaff2a4f59a17e7d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 26 Feb 2019 15:26:55 -0600 Subject: [PATCH 03/19] almost done with checkers base --- CheckersCheckpoint/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/CheckersCheckpoint/Program.cs b/CheckersCheckpoint/Program.cs index f06cd63f..6b7c027e 100644 --- a/CheckersCheckpoint/Program.cs +++ b/CheckersCheckpoint/Program.cs @@ -10,5 +10,6 @@ public static void Main(string[] args) { new Game(); } + } } \ No newline at end of file From 1ef1583aa18b9f6f27c8d262a97735adfc835daa Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 26 Feb 2019 15:47:39 -0600 Subject: [PATCH 04/19] base done prints checkers had an issue with console Encoding solved on board line 92 --- CheckersCheckpoint/Board.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/CheckersCheckpoint/Board.cs b/CheckersCheckpoint/Board.cs index c5007172..4e30bbdc 100644 --- a/CheckersCheckpoint/Board.cs +++ b/CheckersCheckpoint/Board.cs @@ -89,6 +89,7 @@ public void DrawBoard() CreateBoard(); PlaceCheckers(); Console.WriteLine(" 0 1 2 3 4 5 6 7 "); + Console.OutputEncoding = System.Text.Encoding.UTF8; for (int i = 0; i < 8; i++) { Console.WriteLine(i + " " + String.Join(" ", this.Grid[i])); From cacb3e752e441417c14bad1fab7ebc163a688663 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 27 Feb 2019 18:25:50 -0600 Subject: [PATCH 05/19] rudimentary checkers done --- CheckersCheckpoint/Board.cs | 14 +++----------- CheckersCheckpoint/Checker.cs | 4 ++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/CheckersCheckpoint/Board.cs b/CheckersCheckpoint/Board.cs index 4e30bbdc..917421dc 100644 --- a/CheckersCheckpoint/Board.cs +++ b/CheckersCheckpoint/Board.cs @@ -15,16 +15,8 @@ public Board() this.CreateBoard(); return; } - public string[][] Grid - { - get; - set; - } - public List Checkers - { - get; - set; - } + public string[][] Grid { get; set; } + public List Checkers { get; set; } public void CreateBoard() @@ -77,7 +69,7 @@ public void PlaceCheckers() { foreach (var checker in Checkers) { - // Console.WriteLine(checker.Position[0] + " " + checker.Position[1]); + ; this.Grid[checker.Position[0]][checker.Position[1]] = checker.Symbol; } return; diff --git a/CheckersCheckpoint/Checker.cs b/CheckersCheckpoint/Checker.cs index e77bdba1..6b687ce0 100644 --- a/CheckersCheckpoint/Checker.cs +++ b/CheckersCheckpoint/Checker.cs @@ -17,12 +17,12 @@ public Checker(string color, int[] position) if (color == "white") { - circleId = int.Parse(" 25CE", System.Globalization.NumberStyles.HexNumber); + circleId = int.Parse("25CE", System.Globalization.NumberStyles.HexNumber); Color = "white"; } else { - circleId = int.Parse(" 25C9", System.Globalization.NumberStyles.HexNumber); + circleId = int.Parse("25C9", System.Globalization.NumberStyles.HexNumber); Color = "black"; } this.Symbol = char.ConvertFromUtf32(circleId); From b2a16a5d981727e608f191447a4b2528918e555f Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 2 Mar 2019 00:34:06 -0600 Subject: [PATCH 06/19] base setup --- NewCheckers/.vscode/launch.json | 26 +++++++++++++++++++++++ NewCheckers/.vscode/tasks.json | 15 +++++++++++++ NewCheckers/Board.cs | 37 +++++++++++++++++++++++++++++++++ NewCheckers/Checker.cs | 18 ++++++++++++++++ NewCheckers/Coordinates.cs | 15 +++++++++++++ NewCheckers/Game.cs | 9 ++++++++ NewCheckers/NewCheckers.csproj | 8 +++++++ NewCheckers/Program.cs | 12 +++++++++++ 8 files changed, 140 insertions(+) create mode 100644 NewCheckers/.vscode/launch.json create mode 100644 NewCheckers/.vscode/tasks.json create mode 100644 NewCheckers/Board.cs create mode 100644 NewCheckers/Checker.cs create mode 100644 NewCheckers/Coordinates.cs create mode 100644 NewCheckers/Game.cs create mode 100644 NewCheckers/NewCheckers.csproj create mode 100644 NewCheckers/Program.cs diff --git a/NewCheckers/.vscode/launch.json b/NewCheckers/.vscode/launch.json new file mode 100644 index 00000000..d3ae507e --- /dev/null +++ b/NewCheckers/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/NewCheckers.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/NewCheckers/.vscode/tasks.json b/NewCheckers/.vscode/tasks.json new file mode 100644 index 00000000..ab83386f --- /dev/null +++ b/NewCheckers/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/NewCheckers.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/NewCheckers/Board.cs b/NewCheckers/Board.cs new file mode 100644 index 00000000..4868b07f --- /dev/null +++ b/NewCheckers/Board.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; + +namespace NewCheckers +{ + public class Board + { + public Dictionary pieces { get; set; } = new Dictionary(); + + public void board() + { + pieces = new Dictionary(); + } + public static void MoveChecker(Checker piece, Coordinates cords) + { + CheckValidity(piece, cords); + } + private static bool CheckValidity(Checker piece, Coordinates cords) + { + bool valid = false; + bool direction = CheckDirection(piece, cords); + bool space = CheckSpace(piece, cords); + valid = direction && space ? true : false; + return valid; + } + private static bool CheckDirection(Checker piece, Coordinates cords) + { + bool valid = false; + return valid; + } + private static bool CheckSpace(Checker piece, Coordinates cords) + { + bool valid = false; + return valid; + } + } +} diff --git a/NewCheckers/Checker.cs b/NewCheckers/Checker.cs new file mode 100644 index 00000000..e6ffe5df --- /dev/null +++ b/NewCheckers/Checker.cs @@ -0,0 +1,18 @@ +using System; + +namespace NewCheckers +{ + public class Checker + { + public string Color { get; private set; } + public bool King { get; private set; } = false; + public Checker(string color) + { + Color = color == "white" ? "25ce" : "25c9"; + } + public void MakeKing() + { + King = true; + } + } +} diff --git a/NewCheckers/Coordinates.cs b/NewCheckers/Coordinates.cs new file mode 100644 index 00000000..47ffa40c --- /dev/null +++ b/NewCheckers/Coordinates.cs @@ -0,0 +1,15 @@ +using System; + +namespace NewCheckers +{ + public class Coordinates + { + public int X { get; private set; } + public int Y { get; private set; } + public Coordinates(int x, int y) + { + X = x; + Y = y; + } + } +} diff --git a/NewCheckers/Game.cs b/NewCheckers/Game.cs new file mode 100644 index 00000000..46fab4db --- /dev/null +++ b/NewCheckers/Game.cs @@ -0,0 +1,9 @@ +using System; + +namespace NewCheckers +{ + public class Game + { + //request both moves + } +} \ No newline at end of file diff --git a/NewCheckers/NewCheckers.csproj b/NewCheckers/NewCheckers.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/NewCheckers/NewCheckers.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/NewCheckers/Program.cs b/NewCheckers/Program.cs new file mode 100644 index 00000000..e271caa4 --- /dev/null +++ b/NewCheckers/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace NewCheckers +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} From 41194d02483f44f946eecf3e56883a047e94ae04 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 2 Mar 2019 00:34:15 -0600 Subject: [PATCH 07/19] base setup --- NewCheckers/Board.cs | 9 +++++++-- NewCheckers/Checker.cs | 3 ++- NewCheckers/Game.cs | 2 +- NewCheckers/Program.cs | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/NewCheckers/Board.cs b/NewCheckers/Board.cs index 4868b07f..cea5b10e 100644 --- a/NewCheckers/Board.cs +++ b/NewCheckers/Board.cs @@ -13,11 +13,16 @@ public void board() } public static void MoveChecker(Checker piece, Coordinates cords) { - CheckValidity(piece, cords); + bool validChecker = CheckValidity(piece, cords); + if (validChecker) + { + + } } - private static bool CheckValidity(Checker piece, Coordinates cords) + private static bool CheckValidity(Checker piece, Coordinates cords, int PlayerTurn) { bool valid = false; + bool validChecker = IsCheckerValid(PlayerTurn, piece) bool direction = CheckDirection(piece, cords); bool space = CheckSpace(piece, cords); valid = direction && space ? true : false; diff --git a/NewCheckers/Checker.cs b/NewCheckers/Checker.cs index e6ffe5df..f921e765 100644 --- a/NewCheckers/Checker.cs +++ b/NewCheckers/Checker.cs @@ -5,9 +5,10 @@ namespace NewCheckers public class Checker { public string Color { get; private set; } - public bool King { get; private set; } = false; + public bool King { get; private set; } public Checker(string color) { + King = false; Color = color == "white" ? "25ce" : "25c9"; } public void MakeKing() diff --git a/NewCheckers/Game.cs b/NewCheckers/Game.cs index 46fab4db..a94241d7 100644 --- a/NewCheckers/Game.cs +++ b/NewCheckers/Game.cs @@ -4,6 +4,6 @@ namespace NewCheckers { public class Game { - //request both moves + //request both moves controle board } } \ No newline at end of file diff --git a/NewCheckers/Program.cs b/NewCheckers/Program.cs index e271caa4..99a62ada 100644 --- a/NewCheckers/Program.cs +++ b/NewCheckers/Program.cs @@ -6,7 +6,8 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + Game game = new Game(); + game.Run(); } } } From abfef1caa9ef2108e9ff2bd5fb3c2f8b67c5e37c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 2 Mar 2019 00:43:09 -0600 Subject: [PATCH 08/19] base setup --- NewCheckers/Board.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/NewCheckers/Board.cs b/NewCheckers/Board.cs index cea5b10e..556b1e8e 100644 --- a/NewCheckers/Board.cs +++ b/NewCheckers/Board.cs @@ -11,9 +11,9 @@ public void board() { pieces = new Dictionary(); } - public static void MoveChecker(Checker piece, Coordinates cords) + public static void MoveChecker(Checker piece, Coordinates cords, int PlayerTurn) { - bool validChecker = CheckValidity(piece, cords); + bool validChecker = CheckValidity(piece, cords, PlayerTurn); if (validChecker) { @@ -22,20 +22,28 @@ public static void MoveChecker(Checker piece, Coordinates cords) private static bool CheckValidity(Checker piece, Coordinates cords, int PlayerTurn) { bool valid = false; - bool validChecker = IsCheckerValid(PlayerTurn, piece) + bool validChecker = IsCheckerValid(PlayerTurn, piece); bool direction = CheckDirection(piece, cords); bool space = CheckSpace(piece, cords); valid = direction && space ? true : false; return valid; } + private static bool IsCheckerValid(int turn, Checker piece) + { + bool valid = false; + //check checker + return valid; + } private static bool CheckDirection(Checker piece, Coordinates cords) { bool valid = false; + //check direction validity return valid; } private static bool CheckSpace(Checker piece, Coordinates cords) { bool valid = false; + // check landing space validity return valid; } } From 8cd423e94ba8b5d95144d6748e018bc615562602 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 3 Mar 2019 01:49:58 -0600 Subject: [PATCH 09/19] almost have the board setup --- NewCheckers/Board.cs | 69 ++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/NewCheckers/Board.cs b/NewCheckers/Board.cs index 556b1e8e..a5ed99bd 100644 --- a/NewCheckers/Board.cs +++ b/NewCheckers/Board.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; namespace NewCheckers { @@ -10,40 +11,70 @@ public class Board public void board() { pieces = new Dictionary(); + CreateCheckers buildNew = new CreateCheckers(); + pieces = buildNew.InitialCheckers(); } - public static void MoveChecker(Checker piece, Coordinates cords, int PlayerTurn) + + public void ChooseMove(int PlayerTurn) { - bool validChecker = CheckValidity(piece, cords, PlayerTurn); - if (validChecker) + int row = PickRow(); + int column = PickColumn(); + Coordinates from = new Coordinates(row, column); + Checker result; + if (pieces.TryGetValue(from, out result)) { - + if (PlayerTurn == 0 && result.Color == "25ce") + { + int toRow = PickRow(); + int toColumn = PickColumn(); + Coordinates to = new Coordinates(toRow, toColumn); + bool valid = CheckValidity(to, from); + if (valid) + { + pieces[to] = pieces[from]; + pieces[from] = null; + } + } + else if (PlayerTurn == 1 && result.Color == "25c9") + { + int toRow = PickRow(); + int toColumn = PickColumn(); + Coordinates to = new Coordinates(toRow, toColumn); + bool valid = CheckValidity(to, from); + if (valid) + { + pieces[to] = pieces[from]; + pieces[from] = null; + } + } + else + { + Console.Clear(); + Console.WriteLine("Invalid Selection."); + Thread.Sleep(500); + } } + + //if this "cords" (row/column) contains a checker of the Player whos turn this is initiate move checker } - private static bool CheckValidity(Checker piece, Coordinates cords, int PlayerTurn) - { - bool valid = false; - bool validChecker = IsCheckerValid(PlayerTurn, piece); - bool direction = CheckDirection(piece, cords); - bool space = CheckSpace(piece, cords); - valid = direction && space ? true : false; - return valid; - } - private static bool IsCheckerValid(int turn, Checker piece) + private static bool CheckValidity(Coordinates to, Coordinates from) { bool valid = false; - //check checker + bool validDirection = CheckDirection(to, from); + bool space = CheckLanding(to, from); + valid = validDirection && space ? true : false; return valid; } - private static bool CheckDirection(Checker piece, Coordinates cords) + private static bool CheckDirection(Coordinates to, Coordinates from) { bool valid = false; - //check direction validity + //check direction validity. king? if yes can go backwards, player 1 goes one way 2 the other return valid; } - private static bool CheckSpace(Checker piece, Coordinates cords) + private static bool CheckLanding(Coordinates to, Coordinates from) { bool valid = false; - // check landing space validity + // check landing space validity is another checker already here, is it a valid space return valid; } } From a8e94a3079d52593259cad7f19fa7ff82fdb72d0 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 3 Mar 2019 20:09:02 -0600 Subject: [PATCH 10/19] worked on game logic a bit more still have no display --- NewCheckers/Board.cs | 18 +++++++++++------- NewCheckers/Checker.cs | 6 +++--- NewCheckers/Coordinates.cs | 4 ++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/NewCheckers/Board.cs b/NewCheckers/Board.cs index a5ed99bd..0e87f23b 100644 --- a/NewCheckers/Board.cs +++ b/NewCheckers/Board.cs @@ -6,13 +6,14 @@ namespace NewCheckers { public class Board { - public Dictionary pieces { get; set; } = new Dictionary(); + public Dictionary pieces { get; set; } + public static Dictionary StaticBoard { get; set; } public void board() { - pieces = new Dictionary(); + this.pieces = new Dictionary(); CreateCheckers buildNew = new CreateCheckers(); - pieces = buildNew.InitialCheckers(); + this.pieces = buildNew.InitialCheckers(); } public void ChooseMove(int PlayerTurn) @@ -28,11 +29,12 @@ public void ChooseMove(int PlayerTurn) int toRow = PickRow(); int toColumn = PickColumn(); Coordinates to = new Coordinates(toRow, toColumn); + StaticBoard = pieces; bool valid = CheckValidity(to, from); if (valid) { - pieces[to] = pieces[from]; - pieces[from] = null; + this.pieces[to] = pieces[from]; + this.pieces[from] = null; } } else if (PlayerTurn == 1 && result.Color == "25c9") @@ -40,11 +42,12 @@ public void ChooseMove(int PlayerTurn) int toRow = PickRow(); int toColumn = PickColumn(); Coordinates to = new Coordinates(toRow, toColumn); + StaticBoard = pieces; bool valid = CheckValidity(to, from); if (valid) { - pieces[to] = pieces[from]; - pieces[from] = null; + this.pieces[to] = pieces[from]; + this.pieces[from] = null; } } else @@ -68,6 +71,7 @@ private static bool CheckValidity(Coordinates to, Coordinates from) private static bool CheckDirection(Coordinates to, Coordinates from) { bool valid = false; + bool isKing = StaticBoard[to].King; //check direction validity. king? if yes can go backwards, player 1 goes one way 2 the other return valid; } diff --git a/NewCheckers/Checker.cs b/NewCheckers/Checker.cs index f921e765..e194e1ec 100644 --- a/NewCheckers/Checker.cs +++ b/NewCheckers/Checker.cs @@ -8,12 +8,12 @@ public class Checker public bool King { get; private set; } public Checker(string color) { - King = false; - Color = color == "white" ? "25ce" : "25c9"; + this.King = false; + this.Color = color == "white" ? "25ce" : "25c9"; } public void MakeKing() { - King = true; + this.King = true; } } } diff --git a/NewCheckers/Coordinates.cs b/NewCheckers/Coordinates.cs index 47ffa40c..8b36481f 100644 --- a/NewCheckers/Coordinates.cs +++ b/NewCheckers/Coordinates.cs @@ -8,8 +8,8 @@ public class Coordinates public int Y { get; private set; } public Coordinates(int x, int y) { - X = x; - Y = y; + this.X = x; + this.Y = y; } } } From 7363468899cb0fd86ab195c1060b70a6a704a068 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 3 Mar 2019 20:09:14 -0600 Subject: [PATCH 11/19] worked on game logic a bit more still have no display --- NewCheckers/Board.cs | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/NewCheckers/Board.cs b/NewCheckers/Board.cs index 0e87f23b..fd2efacd 100644 --- a/NewCheckers/Board.cs +++ b/NewCheckers/Board.cs @@ -7,7 +7,6 @@ namespace NewCheckers public class Board { public Dictionary pieces { get; set; } - public static Dictionary StaticBoard { get; set; } public void board() { @@ -29,10 +28,11 @@ public void ChooseMove(int PlayerTurn) int toRow = PickRow(); int toColumn = PickColumn(); Coordinates to = new Coordinates(toRow, toColumn); - StaticBoard = pieces; - bool valid = CheckValidity(to, from); + CheckMoveValidity check = new CheckMoveValidity(pieces); + bool valid = check.Validity(to, from); if (valid) { + pieces[check.RemoveMe.X, check.RemoveMe.Y] this.pieces[to] = pieces[from]; this.pieces[from] = null; } @@ -42,8 +42,8 @@ public void ChooseMove(int PlayerTurn) int toRow = PickRow(); int toColumn = PickColumn(); Coordinates to = new Coordinates(toRow, toColumn); - StaticBoard = pieces; - bool valid = CheckValidity(to, from); + CheckMoveValidity check = new CheckMoveValidity(pieces); + bool valid = check.Validity(to, from); if (valid) { this.pieces[to] = pieces[from]; @@ -60,26 +60,5 @@ public void ChooseMove(int PlayerTurn) //if this "cords" (row/column) contains a checker of the Player whos turn this is initiate move checker } - private static bool CheckValidity(Coordinates to, Coordinates from) - { - bool valid = false; - bool validDirection = CheckDirection(to, from); - bool space = CheckLanding(to, from); - valid = validDirection && space ? true : false; - return valid; - } - private static bool CheckDirection(Coordinates to, Coordinates from) - { - bool valid = false; - bool isKing = StaticBoard[to].King; - //check direction validity. king? if yes can go backwards, player 1 goes one way 2 the other - return valid; - } - private static bool CheckLanding(Coordinates to, Coordinates from) - { - bool valid = false; - // check landing space validity is another checker already here, is it a valid space - return valid; - } } } From c1804f9f5468a614082d176b52a82c43913b3075 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 4 Mar 2019 18:33:20 -0600 Subject: [PATCH 12/19] fi8nished board --- NewCheckers/Board.cs | 121 +++++++++++++++++++++++-------------- NewCheckers/Checker.cs | 16 ++++- NewCheckers/Coordinates.cs | 2 +- NewCheckers/Game.cs | 23 +++++++ 4 files changed, 115 insertions(+), 47 deletions(-) diff --git a/NewCheckers/Board.cs b/NewCheckers/Board.cs index fd2efacd..4fc5b7ce 100644 --- a/NewCheckers/Board.cs +++ b/NewCheckers/Board.cs @@ -8,57 +8,90 @@ public class Board { public Dictionary pieces { get; set; } - public void board() + public Board() { - this.pieces = new Dictionary(); - CreateCheckers buildNew = new CreateCheckers(); - this.pieces = buildNew.InitialCheckers(); - } - - public void ChooseMove(int PlayerTurn) - { - int row = PickRow(); - int column = PickColumn(); - Coordinates from = new Coordinates(row, column); - Checker result; - if (pieces.TryGetValue(from, out result)) + pieces = new Dictionary(); + for (int i = 0; i < 8; i++) { - if (PlayerTurn == 0 && result.Color == "25ce") + for (int j = 0; j < 8; j++) { - int toRow = PickRow(); - int toColumn = PickColumn(); - Coordinates to = new Coordinates(toRow, toColumn); - CheckMoveValidity check = new CheckMoveValidity(pieces); - bool valid = check.Validity(to, from); - if (valid) + Coordinates cord = new Coordinates(i, j); + Checker check = null; + switch (i) { - pieces[check.RemoveMe.X, check.RemoveMe.Y] - this.pieces[to] = pieces[from]; - this.pieces[from] = null; + case 0: + if (j % 2 == 0 || j == 0) + { + check = new Checker("black"); + pieces.Add(cord, check); + } + else + { + pieces.Add(cord, null); + } + break; + case 1: + if (j % 2 == 0 || j == 0) + { + pieces.Add(cord, null); + } + else + { + check = new Checker("black"); + pieces.Add(cord, check); + } + break; + case 2: + if (j % 2 == 0 || j == 0) + { + check = new Checker("black"); + pieces.Add(cord, check); + } + else + { + pieces.Add(cord, null); + } + break; + case 5: + if (j % 2 == 0 || j == 0) + { + pieces.Add(cord, null); + } + else + { + check = new Checker("white"); + pieces.Add(cord, check); + } + break; + case 6: + if (j % 2 == 0 || j == 0) + { + check = new Checker("white"); + pieces.Add(cord, check); + } + else + { + pieces.Add(cord, null); + } + break; + case 7: + if (j % 2 == 0 || j == 0) + { + pieces.Add(cord, null); + } + else + { + check = new Checker("white"); + pieces.Add(cord, check); + } + break; + default: + pieces.Add(cord, null); + break; } } - else if (PlayerTurn == 1 && result.Color == "25c9") - { - int toRow = PickRow(); - int toColumn = PickColumn(); - Coordinates to = new Coordinates(toRow, toColumn); - CheckMoveValidity check = new CheckMoveValidity(pieces); - bool valid = check.Validity(to, from); - if (valid) - { - this.pieces[to] = pieces[from]; - this.pieces[from] = null; - } - } - else - { - Console.Clear(); - Console.WriteLine("Invalid Selection."); - Thread.Sleep(500); - } } - - //if this "cords" (row/column) contains a checker of the Player whos turn this is initiate move checker } } } + diff --git a/NewCheckers/Checker.cs b/NewCheckers/Checker.cs index e194e1ec..a4bfb23b 100644 --- a/NewCheckers/Checker.cs +++ b/NewCheckers/Checker.cs @@ -5,11 +5,23 @@ namespace NewCheckers public class Checker { public string Color { get; private set; } + public string ColorAbs { get; private set; } public bool King { get; private set; } public Checker(string color) { - this.King = false; - this.Color = color == "white" ? "25ce" : "25c9"; + int circleId; + + if (color == "white") + { + circleId = int.Parse("25CE", System.Globalization.NumberStyles.HexNumber); + ColorAbs = "white"; + } + else + { + circleId = int.Parse("25CF", System.Globalization.NumberStyles.HexNumber); + ColorAbs = "black"; + } + this.Color = char.ConvertFromUtf32(circleId); } public void MakeKing() { diff --git a/NewCheckers/Coordinates.cs b/NewCheckers/Coordinates.cs index 8b36481f..ff0b1818 100644 --- a/NewCheckers/Coordinates.cs +++ b/NewCheckers/Coordinates.cs @@ -2,7 +2,7 @@ namespace NewCheckers { - public class Coordinates + public struct Coordinates { public int X { get; private set; } public int Y { get; private set; } diff --git a/NewCheckers/Game.cs b/NewCheckers/Game.cs index a94241d7..bd266165 100644 --- a/NewCheckers/Game.cs +++ b/NewCheckers/Game.cs @@ -5,5 +5,28 @@ namespace NewCheckers public class Game { //request both moves controle board + Board CurrentBoard; + public Game() + { + CurrentBoard = new Board(); + } + public void Run() + { + int turn = 1; + bool GameOver = false; + int Winner; + while (!GameOver) + { + Select Choose = new Select(turn, CurrentBoard.pieces); + Coordinates moveFrom = Choose.From(); + Coordinates moveTo = Choose.To(); + bool valid = Choose.CheckValidity(moveFrom, moveTo); + Display disp = new Display(CurrentBoard.pieces); + //disp.printBoard(); + int one = disp.ChooseX(1); + int two = disp.ChooseY(1, one); + Console.WriteLine(one + "," + two); + } + } } } \ No newline at end of file From bb0af5a017ba3b6d2d1a1c87b70b4490fefdf6e1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 4 Mar 2019 18:41:16 -0600 Subject: [PATCH 13/19] fi8nished board --- NewCheckers/CheckLanding.cs | 47 +++++++ NewCheckers/CreateCheckers.cs | 14 ++ NewCheckers/Display.cs | 256 ++++++++++++++++++++++++++++++++++ NewCheckers/IsValid.cs | 54 +++++++ NewCheckers/Select.cs | 37 +++++ 5 files changed, 408 insertions(+) create mode 100644 NewCheckers/CheckLanding.cs create mode 100644 NewCheckers/CreateCheckers.cs create mode 100644 NewCheckers/Display.cs create mode 100644 NewCheckers/IsValid.cs create mode 100644 NewCheckers/Select.cs diff --git a/NewCheckers/CheckLanding.cs b/NewCheckers/CheckLanding.cs new file mode 100644 index 00000000..e3faa549 --- /dev/null +++ b/NewCheckers/CheckLanding.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +namespace NewCheckers +{ + public class CheckLanding + { + public Coordinates remove { get; set; } + public bool Jumped { get; set; } = false; + public CheckLanding() + { + Jumped = false; + } + public bool Run(Coordinates from, Coordinates to, Dictionary curBoard) + { + int x = from.X; + int y = from.Y; + int toX = to.X; + int toY = to.Y; + + List possibles = new List(); + possibles.Add(new Coordinates(x - 1, y - 1)); + possibles.Add(new Coordinates(x - 2, y - 2)); + possibles.Add(new Coordinates(x + 1, y + 1)); + possibles.Add(new Coordinates(x + 2, y + 2)); + possibles.Add(new Coordinates(x - 1, y + 1)); + possibles.Add(new Coordinates(x - 2, y + 2)); + possibles.Add(new Coordinates(x + 1, y - 1)); + possibles.Add(new Coordinates(x + 2, y - 2)); + + bool isValidLanding = false; + + foreach (var item in possibles) + { + if (item.X == to.X && item.Y == to.Y) + { + isValidLanding = true; + } + } + if (isValidLanding) + { + if (toX - 2 == x || ) + } + + } + } +} \ No newline at end of file diff --git a/NewCheckers/CreateCheckers.cs b/NewCheckers/CreateCheckers.cs new file mode 100644 index 00000000..5ec70267 --- /dev/null +++ b/NewCheckers/CreateCheckers.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace NewCheckers +{ + class CreateCheckers + { + Dictionary initialSetup = new Dictionary(); + //public Dictionary InitialCheckers() + //{ + + //} + } +} \ No newline at end of file diff --git a/NewCheckers/Display.cs b/NewCheckers/Display.cs new file mode 100644 index 00000000..7392476c --- /dev/null +++ b/NewCheckers/Display.cs @@ -0,0 +1,256 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NewCheckers +{ + public class Display + { + public Dictionary pieces { get; set; } + private int index = 0; + public Display(Dictionary board) + { + pieces = new Dictionary(); + Coordinates cord; + for (int i = 0; i < 8; i++) + { + for (int j = 0; j < 8; j++) + { + cord = new Coordinates(i, j); + Checker c; + if (board.TryGetValue(cord, out c)) + { + if (c != null) + { + this.pieces.Add(cord, c.Color); + } + } + else + { + this.pieces.Add(cord, " "); + } + } + } + } + public int ChooseX(int player)//ChooseX + { + Console.Clear(); + Coordinates cord; + string returnMe = ""; + Console.CursorVisible = false; + while (returnMe == "") + { + Console.WriteLine("Player " + player + " Choose A Row."); + Console.WriteLine(); + for (int i = 0; i < 8; i++) + { + if (index == i) + { + Console.BackgroundColor = ConsoleColor.Black; + Console.ForegroundColor = ConsoleColor.Red; + Console.Write(i); + Console.Write(" "); + } + else + { + Console.BackgroundColor = ConsoleColor.Black; + Console.ForegroundColor = ConsoleColor.White; + Console.Write(i); + Console.Write(" "); + } + for (int j = 0; j < 8; j++) + { + cord = new Coordinates(i, j); + if (i == 0 || i % 2 == 0) + { + if (j == 0 || j % 2 == 0) + { + Console.BackgroundColor = ConsoleColor.White; + } + else + { + Console.BackgroundColor = ConsoleColor.Black; + } + } + else + { + if (j == 0 || j % 2 == 0) + { + Console.BackgroundColor = ConsoleColor.Black; + } + else + { + Console.BackgroundColor = ConsoleColor.White; + } + } + string value = ""; + if (pieces.TryGetValue(cord, out value)) + { + Console.OutputEncoding = System.Text.Encoding.UTF8; + Console.Write(" "); + if (value == char.ConvertFromUtf32(int.Parse("25CE", System.Globalization.NumberStyles.HexNumber))) + { + value = char.ConvertFromUtf32(int.Parse("25CF", System.Globalization.NumberStyles.HexNumber)); + Console.ForegroundColor = ConsoleColor.Red; + Console.Write(value); + Console.Write(" "); + } + else + { + Console.ForegroundColor = ConsoleColor.Black; + Console.Write(value); + Console.Write(" "); + } + } + else + { + Console.Write(" "); + } + Console.ResetColor(); + } + Console.WriteLine(); + } + List items = new List { "0", "1", "2", "3", "4", "5", "6", "7" }; + returnMe = MenuControllerX(items); + } + index = 0; + return Convert.ToInt32(returnMe); + } + private string MenuControllerX(List items) + { + ConsoleKeyInfo userInput = Console.ReadKey(); + + if (userInput.Key == ConsoleKey.DownArrow) + { + index = index == items.Count - 1 ? 0 : index + 1; + } + else if (userInput.Key == ConsoleKey.UpArrow) + { + index = index <= 0 ? items.Count - 1 : index - 1; + } + else if (userInput.Key == ConsoleKey.Enter) + { + return items[index]; + } + Console.Clear(); + return ""; + } + public int ChooseY(int player, int x)//PickY + { + Console.Clear(); + Coordinates cord; + string returnMe = ""; + Console.CursorVisible = false; + while (returnMe == "") + { + Console.WriteLine("Player " + player + " Choose A Row."); + Console.WriteLine(); + for (int i = 0; i < 8; i++) + { + for (int j = 0; j < 8; j++) + { + cord = new Coordinates(i, j); + + if (i == 0 || i % 2 == 0) + { + if (j == 0 || j % 2 == 0) + { + Console.BackgroundColor = ConsoleColor.White; + } + else + { + Console.BackgroundColor = ConsoleColor.Black; + } + if (i == x && j == index) + { + Console.BackgroundColor = ConsoleColor.Green; + } + } + else + { + if (j == 0 || j % 2 == 0) + { + Console.BackgroundColor = ConsoleColor.Black; + } + else + { + Console.BackgroundColor = ConsoleColor.White; + } + if (i == x && j == index) + { + Console.BackgroundColor = ConsoleColor.Green; + } + } + string value = ""; + if (pieces.TryGetValue(cord, out value)) + { + Console.OutputEncoding = System.Text.Encoding.UTF8; + Console.Write(" "); + if (value == char.ConvertFromUtf32(int.Parse("25CE", System.Globalization.NumberStyles.HexNumber))) + { + value = char.ConvertFromUtf32(int.Parse("25CF", System.Globalization.NumberStyles.HexNumber)); + Console.ForegroundColor = ConsoleColor.Red; + Console.Write(value); + Console.Write(" "); + } + else + { + Console.ForegroundColor = ConsoleColor.Black; + Console.Write(value); + Console.Write(" "); + } + } + else + { + Console.Write(" "); + } + Console.ResetColor(); + } + Console.WriteLine(); + } + List items = new List { "0", "1", "2", "3", "4", "5", "6", "7" }; + for (int i = 0; i < items.Count; i++) + { + if (index == i) + { + Console.BackgroundColor = ConsoleColor.Black; + Console.ForegroundColor = ConsoleColor.Red; + Console.Write(" "); + Console.Write(items[i]); + Console.Write(" "); + } + else + { + Console.BackgroundColor = ConsoleColor.Black; + Console.ForegroundColor = ConsoleColor.White; + Console.Write(" "); + Console.Write(items[i]); + Console.Write(" "); + } + } + returnMe = MenuControllerY(items); + } + return Convert.ToInt32(returnMe); + } + private string MenuControllerY(List items) + { + ConsoleKeyInfo userInput = Console.ReadKey(); + + if (userInput.Key == ConsoleKey.RightArrow) + { + index = index == items.Count - 1 ? 0 : index + 1; + } + else if (userInput.Key == ConsoleKey.LeftArrow) + { + index = index <= 0 ? items.Count - 1 : index - 1; + } + else if (userInput.Key == ConsoleKey.Enter) + { + return items[index]; + } + Console.Clear(); + return ""; + } + + } +} diff --git a/NewCheckers/IsValid.cs b/NewCheckers/IsValid.cs new file mode 100644 index 00000000..66e17a1e --- /dev/null +++ b/NewCheckers/IsValid.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; + +namespace NewCheckers +{ + public class IsValid + { + private int Turn; + private Dictionary CurBoard; + private Coordinates From; + private Coordinates To; + public bool Valid = false; + public Coordinates remove; + public IsValid(int turn, Dictionary curBoard, Coordinates from, Coordinates to) + { + this.CurBoard = curBoard; + this.Turn = turn; + this.From = from; + this.To = to; + } + public bool Run() + { + bool isFromValid = CheckFrom(); + bool isToValid = CheckTo(); + this.Valid = isFromValid && isToValid ? true : false; + return Valid; + } + private bool CheckFrom() + { + bool from; + if (Turn == 1 && CurBoard[From].ColorAbs == "white") + { + from = true; + } + else if (Turn == 2 && CurBoard[From].ColorAbs == "black") + { + from = true; + } + else + { + from = false; + } + return from; + } + private bool CheckTo() + { + bool to = false; + CheckLanding land = new CheckLanding(); + land.Run(From, To, CurBoard); + return to; + } + + } +} diff --git a/NewCheckers/Select.cs b/NewCheckers/Select.cs new file mode 100644 index 00000000..fdff344e --- /dev/null +++ b/NewCheckers/Select.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Threading; + +namespace NewCheckers +{ + public class Select + { + private Dictionary CurBoard; + private int Turn; + public Select(int currentTurn, Dictionary CurrentBoard) + { + CurBoard = CurrentBoard; + Turn = currentTurn; + } + public Coordinates From() + { + Display display = new Display(CurBoard); + int row = display.ChooseX(Turn); + int column = display.ChooseY(Turn, row); + return new Coordinates(row, column); + } + public Coordinates To() + { + Display display = new Display(CurBoard); + int row = display.ChooseX(Turn); + int column = display.ChooseY(Turn, row); + return new Coordinates(row, column); + } + public bool CheckValidity(Coordinates from, Coordinates to) + { + IsValid isValid = new IsValid(Turn, CurBoard, from, to); + bool valid = isValid.Check(); + return valid; + } + } +} \ No newline at end of file From 329981b4b2d36d1fc8d816a437006dff4f801725 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 4 Mar 2019 18:41:52 -0600 Subject: [PATCH 14/19] fi8nished board --- NewCheckers/CheckLanding.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NewCheckers/CheckLanding.cs b/NewCheckers/CheckLanding.cs index e3faa549..17271576 100644 --- a/NewCheckers/CheckLanding.cs +++ b/NewCheckers/CheckLanding.cs @@ -39,7 +39,9 @@ public bool Run(Coordinates from, Coordinates to, Dictionary Date: Tue, 5 Mar 2019 01:11:55 -0600 Subject: [PATCH 15/19] finished for now have issues with being king or not --- NewCheckers/CheckLanding.cs | 56 +++++++++++++++++++++-- NewCheckers/Display.cs | 89 +++++++++++++++++++++++++++++++++++-- NewCheckers/Game.cs | 50 ++++++++++++++++++--- NewCheckers/IsValid.cs | 57 +++++++++++++++++++++--- NewCheckers/Select.cs | 21 ++++++--- 5 files changed, 247 insertions(+), 26 deletions(-) diff --git a/NewCheckers/CheckLanding.cs b/NewCheckers/CheckLanding.cs index 17271576..f692633f 100644 --- a/NewCheckers/CheckLanding.cs +++ b/NewCheckers/CheckLanding.cs @@ -5,8 +5,10 @@ namespace NewCheckers { public class CheckLanding { - public Coordinates remove { get; set; } + public Coordinates Remove { get; set; } public bool Jumped { get; set; } = false; + + public CheckLanding() { Jumped = false; @@ -29,21 +31,69 @@ public bool Run(Coordinates from, Coordinates to, Dictionary pieces { get; set; } private int index = 0; + private Boolean Second = false; + private Coordinates cordsPrior; public Display(Dictionary board) { pieces = new Dictionary(); @@ -32,8 +34,19 @@ public Display(Dictionary board) } } } - public int ChooseX(int player)//ChooseX + public int ChooseX(int player, string one, string two)//ChooseX { + if (one != null && two != null) + { + int x = Convert.ToInt32(one); + int y = Convert.ToInt32(two); + cordsPrior = new Coordinates(x, y); + string testMe = ""; + if (pieces.TryGetValue(cordsPrior, out testMe)) + { + Second = testMe == null ? false : true; + } + } Console.Clear(); Coordinates cord; string returnMe = ""; @@ -47,7 +60,7 @@ public int ChooseX(int player)//ChooseX if (index == i) { Console.BackgroundColor = ConsoleColor.Black; - Console.ForegroundColor = ConsoleColor.Red; + Console.ForegroundColor = ConsoleColor.Green; Console.Write(i); Console.Write(" "); } @@ -66,10 +79,24 @@ public int ChooseX(int player)//ChooseX if (j == 0 || j % 2 == 0) { Console.BackgroundColor = ConsoleColor.White; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } } else { Console.BackgroundColor = ConsoleColor.Black; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } } } else @@ -77,10 +104,24 @@ public int ChooseX(int player)//ChooseX if (j == 0 || j % 2 == 0) { Console.BackgroundColor = ConsoleColor.Black; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } } else { Console.BackgroundColor = ConsoleColor.White; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } } } string value = ""; @@ -92,6 +133,7 @@ public int ChooseX(int player)//ChooseX { value = char.ConvertFromUtf32(int.Parse("25CF", System.Globalization.NumberStyles.HexNumber)); Console.ForegroundColor = ConsoleColor.Red; + Console.Write(value); Console.Write(" "); } @@ -135,8 +177,19 @@ private string MenuControllerX(List items) Console.Clear(); return ""; } - public int ChooseY(int player, int x)//PickY + public int ChooseY(int player, int x, string one, string two)//PickY { + if (one != null && two != null) + { + int z = Convert.ToInt32(one); + int y = Convert.ToInt32(two); + cordsPrior = new Coordinates(z, y); + string testMe = ""; + if (pieces.TryGetValue(cordsPrior, out testMe)) + { + Second = testMe == null ? false : true; + } + } Console.Clear(); Coordinates cord; string returnMe = ""; @@ -156,10 +209,24 @@ public int ChooseY(int player, int x)//PickY if (j == 0 || j % 2 == 0) { Console.BackgroundColor = ConsoleColor.White; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } } else { Console.BackgroundColor = ConsoleColor.Black; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } } if (i == x && j == index) { @@ -171,10 +238,24 @@ public int ChooseY(int player, int x)//PickY if (j == 0 || j % 2 == 0) { Console.BackgroundColor = ConsoleColor.Black; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } } else { Console.BackgroundColor = ConsoleColor.White; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } } if (i == x && j == index) { @@ -214,7 +295,7 @@ public int ChooseY(int player, int x)//PickY if (index == i) { Console.BackgroundColor = ConsoleColor.Black; - Console.ForegroundColor = ConsoleColor.Red; + Console.ForegroundColor = ConsoleColor.Green; Console.Write(" "); Console.Write(items[i]); Console.Write(" "); diff --git a/NewCheckers/Game.cs b/NewCheckers/Game.cs index bd266165..9f3b885b 100644 --- a/NewCheckers/Game.cs +++ b/NewCheckers/Game.cs @@ -10,6 +10,8 @@ public Game() { CurrentBoard = new Board(); } + public int White = 0; + public int Black = 0; public void Run() { int turn = 1; @@ -19,14 +21,48 @@ public void Run() { Select Choose = new Select(turn, CurrentBoard.pieces); Coordinates moveFrom = Choose.From(); - Coordinates moveTo = Choose.To(); + Coordinates moveTo = Choose.To(moveFrom); bool valid = Choose.CheckValidity(moveFrom, moveTo); - Display disp = new Display(CurrentBoard.pieces); - //disp.printBoard(); - int one = disp.ChooseX(1); - int two = disp.ChooseY(1, one); - Console.WriteLine(one + "," + two); + + if (valid) + { + CurrentBoard.pieces[moveTo] = CurrentBoard.pieces[moveFrom]; + CurrentBoard.pieces[moveFrom] = null; + if (moveTo.X == 0 && turn == 1) + { + this.CurrentBoard.pieces[moveTo].MakeKing(); + } + if (moveTo.X == 7 && turn == 2) + { + this.CurrentBoard.pieces[moveTo].MakeKing(); + } + if (Choose.Jumped == true) + { + bool addPoint = CurrentBoard.pieces[Choose.Remove].ColorAbs == "white" ? true : false; + this.CurrentBoard.pieces[Choose.Remove] = null; + if (addPoint) + { + this.White++; + } + else + { + this.Black++; + } + } + + turn = turn == 1 ? 2 : 1; + } + + GameOver = White == 12 || Black == 12 ? true : false; + if (GameOver) + { + Winner = White == 12 ? 1 : 2; + } + } } } -} \ No newline at end of file +} +/*Display display = new Display(CurrentBoard.pieces); + int one = display.ChooseX(1); + int two = display.ChooseY(1, one); */ diff --git a/NewCheckers/IsValid.cs b/NewCheckers/IsValid.cs index 66e17a1e..56923edb 100644 --- a/NewCheckers/IsValid.cs +++ b/NewCheckers/IsValid.cs @@ -10,7 +10,8 @@ public class IsValid private Coordinates From; private Coordinates To; public bool Valid = false; - public Coordinates remove; + public Coordinates Remove; + public bool Jumped = false; public IsValid(int turn, Dictionary curBoard, Coordinates from, Coordinates to) { this.CurBoard = curBoard; @@ -20,19 +21,21 @@ public IsValid(int turn, Dictionary curBoard, Coordinates } public bool Run() { - bool isFromValid = CheckFrom(); - bool isToValid = CheckTo(); + bool isFromValid = false; + bool isToValid = false; + isFromValid = CheckFrom(); + isToValid = CheckTo(); this.Valid = isFromValid && isToValid ? true : false; return Valid; } private bool CheckFrom() { bool from; - if (Turn == 1 && CurBoard[From].ColorAbs == "white") + if (Turn == 1 && CurBoard[From] != null && CurBoard[From].ColorAbs == "white") { from = true; } - else if (Turn == 2 && CurBoard[From].ColorAbs == "black") + else if (Turn == 2 && CurBoard[From] != null && CurBoard[From].ColorAbs == "black") { from = true; } @@ -46,7 +49,49 @@ private bool CheckTo() { bool to = false; CheckLanding land = new CheckLanding(); - land.Run(From, To, CurBoard); + to = land.Run(From, To, CurBoard); + if (land.Jumped) + { + this.Remove = land.Remove; + this.Jumped = true; + } + if (Turn == 1 && (From.X - To.X) < 0) + { + Checker tryMe; + if (!CurBoard.TryGetValue(From, out tryMe)) + { + if (tryMe != null) + { + if (!tryMe.King) + { + to = false; + } + } + } + else + { + to = false; + } + } + if (Turn == 2 && (To.X - From.X) < 0) + { + Checker tryMe; + if (!CurBoard.TryGetValue(From, out tryMe)) + { + if (tryMe != null && !tryMe.King) + if (tryMe != null) + { + if (!tryMe.King) + { + to = false; + } + } + } + else + { + to = false; + } + } return to; } diff --git a/NewCheckers/Select.cs b/NewCheckers/Select.cs index fdff344e..05f35731 100644 --- a/NewCheckers/Select.cs +++ b/NewCheckers/Select.cs @@ -8,6 +8,8 @@ public class Select { private Dictionary CurBoard; private int Turn; + public bool Jumped = false; + public Coordinates Remove; public Select(int currentTurn, Dictionary CurrentBoard) { CurBoard = CurrentBoard; @@ -16,21 +18,28 @@ public Select(int currentTurn, Dictionary CurrentBoard) public Coordinates From() { Display display = new Display(CurBoard); - int row = display.ChooseX(Turn); - int column = display.ChooseY(Turn, row); + int row = display.ChooseX(Turn, null, null); + int column = display.ChooseY(Turn, row, null, null); return new Coordinates(row, column); } - public Coordinates To() + public Coordinates To(Coordinates old) { + string x = old.X.ToString(); + string y = old.Y.ToString(); Display display = new Display(CurBoard); - int row = display.ChooseX(Turn); - int column = display.ChooseY(Turn, row); + int row = display.ChooseX(Turn, x, y); + int column = display.ChooseY(Turn, row, x, y); return new Coordinates(row, column); } public bool CheckValidity(Coordinates from, Coordinates to) { IsValid isValid = new IsValid(Turn, CurBoard, from, to); - bool valid = isValid.Check(); + bool valid = isValid.Run(); + if (isValid.Jumped) + { + this.Jumped = true; + this.Remove = isValid.Remove; + } return valid; } } From 2d4debc6a352f92fb54fffadabad95055349ce1e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Mar 2019 18:23:04 -0600 Subject: [PATCH 16/19] added king system --- NewCheckers/Game.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/NewCheckers/Game.cs b/NewCheckers/Game.cs index 9f3b885b..e17f3317 100644 --- a/NewCheckers/Game.cs +++ b/NewCheckers/Game.cs @@ -58,7 +58,6 @@ public void Run() { Winner = White == 12 ? 1 : 2; } - } } } From aea114ad75145965543b8773d0a8a87d9339ad7b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Mar 2019 19:28:14 -0600 Subject: [PATCH 17/19] 0 --- NewCheckers/IsValid.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/NewCheckers/IsValid.cs b/NewCheckers/IsValid.cs index 56923edb..2079920c 100644 --- a/NewCheckers/IsValid.cs +++ b/NewCheckers/IsValid.cs @@ -70,7 +70,13 @@ private bool CheckTo() } else { - to = false; + if (tryMe != null) + { + if (!tryMe.King) + { + to = false; + } + } } } if (Turn == 2 && (To.X - From.X) < 0) From 5eb441f7f8afb2643cbc1ca4067c73b1780979bd Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Mar 2019 19:30:48 -0600 Subject: [PATCH 18/19] 0 --- NewCheckers/IsValid.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/NewCheckers/IsValid.cs b/NewCheckers/IsValid.cs index 2079920c..ee96a584 100644 --- a/NewCheckers/IsValid.cs +++ b/NewCheckers/IsValid.cs @@ -58,7 +58,8 @@ private bool CheckTo() if (Turn == 1 && (From.X - To.X) < 0) { Checker tryMe; - if (!CurBoard.TryGetValue(From, out tryMe)) + + if (CurBoard.TryGetValue(From, out tryMe)) { if (tryMe != null) { @@ -70,19 +71,13 @@ private bool CheckTo() } else { - if (tryMe != null) - { - if (!tryMe.King) - { - to = false; - } - } + to = false; } } if (Turn == 2 && (To.X - From.X) < 0) { Checker tryMe; - if (!CurBoard.TryGetValue(From, out tryMe)) + if (CurBoard.TryGetValue(From, out tryMe)) { if (tryMe != null && !tryMe.King) if (tryMe != null) From 124fb2327e89311ee8f965e50506edfa998830c3 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Mar 2019 21:22:26 -0600 Subject: [PATCH 19/19] forcing me to commit nothing --- NewCheckers/IsValid.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/NewCheckers/IsValid.cs b/NewCheckers/IsValid.cs index ee96a584..bdb5a0c9 100644 --- a/NewCheckers/IsValid.cs +++ b/NewCheckers/IsValid.cs @@ -58,7 +58,6 @@ private bool CheckTo() if (Turn == 1 && (From.X - To.X) < 0) { Checker tryMe; - if (CurBoard.TryGetValue(From, out tryMe)) { if (tryMe != null)