From b25f5eb332118123742cf9286d0a28d3d6f50fc0 Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Wed, 22 Aug 2018 14:27:25 -0500 Subject: [PATCH 1/8] started whiteboarding checkers --- checkpoint2/Program.cs | 79 ++++++++++++++++++++++++++++++++++ checkpoint2/checkpoint2.csproj | 8 ++++ 2 files changed, 87 insertions(+) create mode 100644 checkpoint2/Program.cs create mode 100644 checkpoint2/checkpoint2.csproj diff --git a/checkpoint2/Program.cs b/checkpoint2/Program.cs new file mode 100644 index 00000000..bfa30cd2 --- /dev/null +++ b/checkpoint2/Program.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; + +namespace checkpoint2 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + Game myGame = new Game(); + + } + } + public class Game + { + //the only thing in the Game class should be the Start method + public void Start() + { + + } + } + public class Board + { + public String[][] Grid {get;set;} + public List Checkers {get;set;} + + //this is where we will need to build some methods to CreateBoard, DrawBoard, GenerateBoard, SelectChecker, RemoveChecker, and CheckForWin + + public void DrawBoard() + { + Console.WriteLine(" 0 1 2 3 4 5 6 7 "); + Console.WriteLine(); + Console.WriteLine("0"); + Console.WriteLine(); + Console.WriteLine("1"); + Console.WriteLine(); + Console.WriteLine("2"); + Console.WriteLine(); + Console.WriteLine("3"); + Console.WriteLine(); + Console.WriteLine("4"); + Console.WriteLine(); + Console.WriteLine("5"); + Console.WriteLine(); + Console.WriteLine("6"); + Console.WriteLine(); + Console.WriteLine("7"); + } + + + } + public class Checker + { + public String symbol {get;set;} + public String color {get;set;} + public int[] position {get;set;} + + public Checker(String color, int[] position) + { + this.color = color; + this.symbol = symbol; + this.position = position; + int openCircleId = int.Parse("25CB", System.Globalization.NumberStyles.HexNumber); + int closedCircleId = int.Parse("25CF", System.Globalization.NumberStyles.HexNumber); + if (color == "white") + { + string openCircle = char.ConvertFromUtf32(openCircleId); + symbol = openCircle; + } + else + { + string closedCircle = char.ConvertFromUtf32(closedCircleId); + symbol = closedCircle; + } + } + } + +} diff --git a/checkpoint2/checkpoint2.csproj b/checkpoint2/checkpoint2.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/checkpoint2/checkpoint2.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + From a4cdd18bf6271dbc2e04ab1bbd2350966e4b1e08 Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Wed, 22 Aug 2018 19:39:46 -0500 Subject: [PATCH 2/8] working on checkerboard --- checkpoint2/.vscode/launch.json | 28 +++++++++++++++++ checkpoint2/.vscode/tasks.json | 15 ++++++++++ checkpoint2/Program.cs | 53 +++++++++++++++++---------------- 3 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 checkpoint2/.vscode/launch.json create mode 100644 checkpoint2/.vscode/tasks.json diff --git a/checkpoint2/.vscode/launch.json b/checkpoint2/.vscode/launch.json new file mode 100644 index 00000000..d4c22ca1 --- /dev/null +++ b/checkpoint2/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/checkpoint2.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ,] +} \ No newline at end of file diff --git a/checkpoint2/.vscode/tasks.json b/checkpoint2/.vscode/tasks.json new file mode 100644 index 00000000..74d1b874 --- /dev/null +++ b/checkpoint2/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/checkpoint2.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/checkpoint2/Program.cs b/checkpoint2/Program.cs index bfa30cd2..341b00df 100644 --- a/checkpoint2/Program.cs +++ b/checkpoint2/Program.cs @@ -7,9 +7,9 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + Console.WriteLine("Checkerspoint 2"); Game myGame = new Game(); - + myGame.Start(); } } public class Game @@ -17,43 +17,46 @@ public class Game //the only thing in the Game class should be the Start method public void Start() { - + Board aBoard = new Board(); + aBoard.DrawBoard(); } + public Game(){} } public class Board { - public String[][] Grid {get;set;} - public List Checkers {get;set;} + // public String[,] grid {get;set;} //need 8 rows, 8 columns + public String[,] grid = new String[8,8]; + public List checkers {get;set;} + public Board() + { + // this.grid = grid; + List checkers = new List(); + } - //this is where we will need to build some methods to CreateBoard, DrawBoard, GenerateBoard, SelectChecker, RemoveChecker, and CheckForWin + //this is where we will need to build some methods to CreateBoard(board constructor), DrawBoard, GenerateBoard, SelectChecker, CheckValidMove(checkerposition[],tox,toy)RETURNBOOL, MoveChecker, RemoveChecker, and CheckForWin(take in color, did white win true false) + //when we instantiate a checker, we gotsta add it to the list at the same time yo + //selectchecker takes in x,y, returns checker or null, or throws exception public void DrawBoard() { - Console.WriteLine(" 0 1 2 3 4 5 6 7 "); - Console.WriteLine(); - Console.WriteLine("0"); - Console.WriteLine(); - Console.WriteLine("1"); - Console.WriteLine(); - Console.WriteLine("2"); - Console.WriteLine(); - Console.WriteLine("3"); - Console.WriteLine(); - Console.WriteLine("4"); - Console.WriteLine(); - Console.WriteLine("5"); - Console.WriteLine(); - Console.WriteLine("6"); - Console.WriteLine(); - Console.WriteLine("7"); + Console.WriteLine(" 0 1 2 3 4 5 6 7 "); //what i need to do is probably do a console writeline for each row of the grid 2d array with probably 2 for loops, ie, for each row, then for each item in each row + for (int i = 0; i < grid.GetLength(0); i++) + { + Console.Write(i + ": "); + for (int j = 0; j < grid.GetLength(1); j++) + { + Console.Write(grid[i,j]); + } + Console.WriteLine(); + } } } public class Checker { - public String symbol {get;set;} - public String color {get;set;} + public String symbol {get;private set;} + public String color {get;private set;} public int[] position {get;set;} public Checker(String color, int[] position) From c8d267b7df9294b016436933369a8e6b290048fd Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Sun, 26 Aug 2018 09:05:50 -0500 Subject: [PATCH 3/8] working on cp 2 --- checkpoint2/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkpoint2/Program.cs b/checkpoint2/Program.cs index 341b00df..12b71e9b 100644 --- a/checkpoint2/Program.cs +++ b/checkpoint2/Program.cs @@ -39,7 +39,7 @@ public Board() public void DrawBoard() { - Console.WriteLine(" 0 1 2 3 4 5 6 7 "); //what i need to do is probably do a console writeline for each row of the grid 2d array with probably 2 for loops, ie, for each row, then for each item in each row + Console.WriteLine(" 0 1 2 3 4 5 6 7 "); for (int i = 0; i < grid.GetLength(0); i++) { Console.Write(i + ": "); From 903578085418e24959956c4c66c9efa7d412abfa Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Mon, 27 Aug 2018 18:30:31 -0500 Subject: [PATCH 4/8] continuing work on checkpoint --- checkpoint2/Program.cs | 187 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 171 insertions(+), 16 deletions(-) diff --git a/checkpoint2/Program.cs b/checkpoint2/Program.cs index 12b71e9b..2c64c99e 100644 --- a/checkpoint2/Program.cs +++ b/checkpoint2/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections.Generic; namespace checkpoint2 @@ -10,46 +11,187 @@ static void Main(string[] args) Console.WriteLine("Checkerspoint 2"); Game myGame = new Game(); myGame.Start(); + } } public class Game { - //the only thing in the Game class should be the Start method + //"the only thing in the Game class should be the Start method" public void Start() { Board aBoard = new Board(); - aBoard.DrawBoard(); + // Console.WriteLine(int.Parse("25CB", System.Globalization.NumberStyles.HexNumber)); + // Console.WriteLine(int.Parse("25CF", System.Globalization.NumberStyles.HexNumber)); + aBoard.GenerateCheckers(); + while (!aBoard.hasWon) + { + aBoard.SwitchPlayers(); + aBoard.PlaceCheckers(); + aBoard.DrawBoard(); + aBoard.MoveChecker(); + } } public Game(){} } public class Board { - // public String[,] grid {get;set;} //need 8 rows, 8 columns public String[,] grid = new String[8,8]; + public bool hasWon = false; + public string playerColor = "white"; public List checkers {get;set;} public Board() { - // this.grid = grid; - List checkers = new List(); + this.checkers = new List(); } - //this is where we will need to build some methods to CreateBoard(board constructor), DrawBoard, GenerateBoard, SelectChecker, CheckValidMove(checkerposition[],tox,toy)RETURNBOOL, MoveChecker, RemoveChecker, and CheckForWin(take in color, did white win true false) - //when we instantiate a checker, we gotsta add it to the list at the same time yo - //selectchecker takes in x,y, returns checker or null, or throws exception - public void DrawBoard() { - Console.WriteLine(" 0 1 2 3 4 5 6 7 "); + + Console.WriteLine(" 01234567"); for (int i = 0; i < grid.GetLength(0); i++) { Console.Write(i + ": "); for (int j = 0; j < grid.GetLength(1); j++) { + if (grid[i,j] == null) // if spot on grid doesnt have a checker, a space is written so the spacing doesnt get all fucked up + { + Console.Write(" "); + } Console.Write(grid[i,j]); } Console.WriteLine(); } } + public void GenerateCheckers(){ // generate checkers only runs once at the beginning of the game. it creates all of the white and black checkers and gives them the correct coords + for (int i = 0; i < 3; i++) // iterate through columns where whites should go + { + for (int j = 0; j < 8; j++) //iterate through rows + { + if ((i % 2 == 0 && j % 2 != 0) || (i % 2 != 0 && j % 2 == 0)) + { + checkers.Add(new Checker(true, i,j)); + } + } + } + //for black + for (int i = 5; i < 8; i++) // iterate through columns where black should go + { + for (int j = 0; j < 8; j++) //iterate through rows + { + if ((i % 2 == 0 && j % 2 != 0) || (i % 2 != 0 && j % 2 == 0)) + { + checkers.Add(new Checker(false, i, j)); + // Console.WriteLine("adding black checker to list at coordinate {0} {1}", i,j); + } + } + } + + // foreach (Checker c in checkers) //INTIAL CHECKER PLACEMENT CHECK + // { + // Console.WriteLine("Checker at X " + c.xPos + " and Y " + c.yPos); + // } + + } + public void PlaceCheckers() //this is what reads the checker coordinates and puts it in the grid in the right place + { + for (var i = 0; i < checkers.Count; i++) + { + int[] position = checkers[i].position; + grid[position[0],position[1]] = checkers[i].symbol; + } + return; + } + public void MoveChecker(){ + + int[] validInput = new int[] {0,1,2,3,4,5,6,7}; + Console.WriteLine("Enter Pickup Row: "); + int fromX = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Enter Pickup Column: "); + int fromY = Convert.ToInt32(Console.ReadLine()); + Checker checkerToMove = SelectChecker(fromX, fromY); + + if (!validInput.Contains(fromX) || !validInput.Contains(fromY)) // CHECKS IF INPUT IS OUT OF BOUNDS + { + Console.WriteLine("Your selection is out of bounds of the board"); + return; + } + else if (checkerToMove == null) // CHECKS IF A CHECKER IS THERE + { + Console.WriteLine("You chose an empty space. Please choose again."); + return; + } + else if (checkerToMove.color != playerColor) //CHECKS TO SEE IF IT'S THE RIGHT PLAYER's CHECKER + { + Console.WriteLine("You chose the wrong colored checker. Please choose again."); + return; + } + + + Console.WriteLine("Enter Placement Row: "); + int toX = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Enter Placement Column: "); + int toY = Convert.ToInt32(Console.ReadLine()); + + + //DO CHECKS HERE + //if y or x are lower than 0, or if y or x are greater than 7 don't allow + if (!validInput.Contains(toX) || !validInput.Contains(toY)) // CHECKS IF DESTINATION IS OUT OF BOUNDS + { + Console.WriteLine("Your destination is out of bounds of the board"); + return; + } + //destination cant have another checker of the same color + if ((grid[toX,toY] != null) && (SelectChecker(toX, toY).color == checkerToMove.color)) //CHECKS IF DESTINATION HAS A CHECKER OF THE SAME COLOR + { + Console.WriteLine("You aren't allowed to land on another checker of your color"); + return; + } + //blacks can only move y-1 and either x-1 or x+1 + if (Math.Abs(fromY - toY) > 1 || Math.Abs(fromX - toX) > 1) + { + Console.WriteLine("Your destination is illegal. You can only move diagonally 1 space. If you want to jump an enemy checker, choose it's location."); + return; + } + //whites can only move y+1 and either x-1 or x+1 + + // if opposite colored checker is in location where you want to jump, double the move (if its x+1 and y+1 do x+2 and y+2) + //also let the same player go again if they take out a checker, so they can chain jumps, but they cant change checkers (not sure how to do this yet) + + checkerToMove.position[0] = toX; + checkerToMove.position[1] = toY; + + grid[fromX,fromY] = null; + + // foreach (Checker c in checkers) // this is just a console for troubleshooting to ensure that the coordinates of the checkers are really updating + // { + // Console.WriteLine(c.color + " checker at X " + c.xPos + " and Y " + c.yPos); + // } + } + + public Checker SelectChecker(int row, int column) //selectchecker takes in x,y, returns checker or null, or throws exception + { + return checkers.Find(x => x.position.SequenceEqual(new List { row, column })); + } + + public bool CheckForWin() + { + return checkers.All(x => x.color == "white") || !checkers.Exists(x => x.color == "white"); + } + + public void SwitchPlayers() + { + if (playerColor == "white") + { + Console.WriteLine("White Turn"); + playerColor = "black"; + } + else + { + Console.WriteLine("Black Turn"); + playerColor = "white"; + } + } + } @@ -57,24 +199,37 @@ public class Checker { public String symbol {get;private set;} public String color {get;private set;} - public int[] position {get;set;} + public int[] position = new int[2]; + public bool isWhite {get;private set;} - public Checker(String color, int[] position) + public int xPos {get;set;} + public int yPos {get;set;} + + public Checker(bool isWhite, int xPos, int yPos) { + this.color = color; this.symbol = symbol; - this.position = position; int openCircleId = int.Parse("25CB", System.Globalization.NumberStyles.HexNumber); int closedCircleId = int.Parse("25CF", System.Globalization.NumberStyles.HexNumber); - if (color == "white") + this.xPos = xPos; + this.yPos = yPos; + position[0] = xPos; + position[1] = yPos; + + if (isWhite) { + color = "white"; string openCircle = char.ConvertFromUtf32(openCircleId); - symbol = openCircle; + // symbol = openCircle; + symbol = "X"; } else { + color = "black"; string closedCircle = char.ConvertFromUtf32(closedCircleId); - symbol = closedCircle; + // symbol = closedCircle; + symbol = "O"; } } } From f1dd04cb3ad528eeade7b7468733c8d226a9c05b Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Tue, 28 Aug 2018 11:44:14 -0500 Subject: [PATCH 5/8] still working on checkpoint2 --- practice2/.vscode/launch.json | 28 ++++++++++++++++++++++++++++ practice2/.vscode/tasks.json | 15 +++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 practice2/.vscode/launch.json create mode 100644 practice2/.vscode/tasks.json diff --git a/practice2/.vscode/launch.json b/practice2/.vscode/launch.json new file mode 100644 index 00000000..23303620 --- /dev/null +++ b/practice2/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/practice2.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ,] +} \ No newline at end of file diff --git a/practice2/.vscode/tasks.json b/practice2/.vscode/tasks.json new file mode 100644 index 00000000..44bc3e38 --- /dev/null +++ b/practice2/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/practice2.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file From 45e9e4c7b791b667af3378e6a555d723b908cf5b Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Sun, 2 Sep 2018 14:37:29 -0500 Subject: [PATCH 6/8] close to finishing checkers --- checkpoint2/Program.cs | 261 +++++++++++++++++++++++++++++++---------- 1 file changed, 200 insertions(+), 61 deletions(-) diff --git a/checkpoint2/Program.cs b/checkpoint2/Program.cs index 2c64c99e..03190ae3 100644 --- a/checkpoint2/Program.cs +++ b/checkpoint2/Program.cs @@ -8,7 +8,7 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Checkerspoint 2"); + Console.WriteLine("Checkerspoint 2. WHITE = X BLACK = O. WHITE GOES FIRST!"); Game myGame = new Game(); myGame.Start(); @@ -25,11 +25,11 @@ public void Start() aBoard.GenerateCheckers(); while (!aBoard.hasWon) { - aBoard.SwitchPlayers(); aBoard.PlaceCheckers(); aBoard.DrawBoard(); aBoard.MoveChecker(); - } + } + aBoard.WhoWon(); } public Game(){} } @@ -39,6 +39,8 @@ public class Board public bool hasWon = false; public string playerColor = "white"; public List checkers {get;set;} + public int whiteScore {get;set;} + public int blackScore {get;set;} public Board() { this.checkers = new List(); @@ -47,17 +49,17 @@ public Board() public void DrawBoard() { - Console.WriteLine(" 01234567"); + Console.WriteLine(" 0 1 2 3 4 5 6 7 "); for (int i = 0; i < grid.GetLength(0); i++) { - Console.Write(i + ": "); + Console.Write(i + ":"); for (int j = 0; j < grid.GetLength(1); j++) { if (grid[i,j] == null) // if spot on grid doesnt have a checker, a space is written so the spacing doesnt get all fucked up { Console.Write(" "); } - Console.Write(grid[i,j]); + Console.Write(" " + grid[i,j]); } Console.WriteLine(); } @@ -73,7 +75,6 @@ public void GenerateCheckers(){ // generate checkers only runs once at the begin } } } - //for black for (int i = 5; i < 8; i++) // iterate through columns where black should go { for (int j = 0; j < 8; j++) //iterate through rows @@ -104,68 +105,191 @@ public void PlaceCheckers() //this is what reads the checker coordinates and put public void MoveChecker(){ int[] validInput = new int[] {0,1,2,3,4,5,6,7}; - Console.WriteLine("Enter Pickup Row: "); - int fromX = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("Enter Pickup Column: "); - int fromY = Convert.ToInt32(Console.ReadLine()); - Checker checkerToMove = SelectChecker(fromX, fromY); + int fromX = 0; + int fromY = 0; + int toX = 0; + int toY = 0; + string input = ""; - if (!validInput.Contains(fromX) || !validInput.Contains(fromY)) // CHECKS IF INPUT IS OUT OF BOUNDS - { - Console.WriteLine("Your selection is out of bounds of the board"); - return; - } - else if (checkerToMove == null) // CHECKS IF A CHECKER IS THERE - { - Console.WriteLine("You chose an empty space. Please choose again."); - return; + PlayerMove(); + + void PlayerMove(){ + GetPlayerInputFrom(); + // CheckPlayerInputFrom(); + // GetPlayerInputTo(); + // CheckPlayerMove(); + // SwitchPlayers(); } - else if (checkerToMove.color != playerColor) //CHECKS TO SEE IF IT'S THE RIGHT PLAYER's CHECKER - { - Console.WriteLine("You chose the wrong colored checker. Please choose again."); - return; + + void GetPlayerInputFrom(){ + //GETTING PLAYER INPUT / FROM + Console.WriteLine("Enter Pickup Row, or type \"c\" to call it a day and tally up the final score: "); + input = Console.ReadLine(); + if (input.ToLower() == "c") + { + CallItADay(); + return; + + } + if(!Int32.TryParse(input, out fromX)) + { + System.Console.WriteLine("Your input is invalid. Only input numbers 0-7. Try again."); + return; + } + + Console.WriteLine("Enter Pickup Column: "); + input = Console.ReadLine(); + if(!Int32.TryParse(input, out fromY)) + { + System.Console.WriteLine("Your input is invalid. Only input numbers 0-7. Try again."); + return; + } + CheckPlayerInputFrom(); } - Console.WriteLine("Enter Placement Row: "); - int toX = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("Enter Placement Column: "); - int toY = Convert.ToInt32(Console.ReadLine()); + void CheckPlayerInputFrom(){ + //INPUT CHECKS / FROM + Checker checkerToMove = SelectChecker(fromX, fromY); + if (!validInput.Contains(fromX) || !validInput.Contains(fromY)) // CHECKS IF INPUT IS OUT OF BOUNDS + { + Console.WriteLine("Your selection is out of bounds of the board"); + return; + } + else if (checkerToMove == null) // CHECKS IF A CHECKER IS THERE + { + Console.WriteLine("You chose an empty space. Please choose again."); + return; + } + else if (checkerToMove.color != playerColor) //CHECKS TO SEE IF IT'S THE RIGHT PLAYER's CHECKER + { + Console.WriteLine("You chose the wrong colored checker. Please choose again."); + return; + } + GetPlayerInputTo(); + } + void GetPlayerInputTo(){ + //GETTING PLAYER INPUT / TO + Console.WriteLine("Enter Placement Row: "); + input = Console.ReadLine(); + if(!Int32.TryParse(input, out toX)) + { + System.Console.WriteLine("Your input is invalid. Only input numbers 0-7. Try again."); + return; + } + Console.WriteLine("Enter Placement Column: "); + input = Console.ReadLine(); + if(!Int32.TryParse(input, out toY)) + { + System.Console.WriteLine("Your input is invalid. Only input numbers 0-7. Try again."); + return; + } + CheckPlayerMove(); + } - //DO CHECKS HERE - //if y or x are lower than 0, or if y or x are greater than 7 don't allow - if (!validInput.Contains(toX) || !validInput.Contains(toY)) // CHECKS IF DESTINATION IS OUT OF BOUNDS + void CheckPlayerMove(){ + //MOVEMENT CHECKS / TO + Checker checkerToMove = SelectChecker(fromX, fromY); + if (!validInput.Contains(toX) || !validInput.Contains(toY)) // CHECKS IF DESTINATION IS OUT OF BOUNDS + { + Console.WriteLine("Your destination is out of bounds of the board"); + return; + } + if ((grid[toX,toY] != null) && (SelectChecker(toX, toY).color == checkerToMove.color)) //CHECKS IF DESTINATION HAS A CHECKER OF THE SAME COLOR + { + Console.WriteLine("You aren't allowed to land on another checker of your color"); + return; + } + if (Math.Abs(fromY - toY) > 1 || Math.Abs(fromX - toX) > 1) //making sure coordinate only increases by 1 + { + Console.WriteLine("Your destination is illegal. You can only move diagonally 1 space. If you want to jump an enemy checker, choose it's location."); + return; + } + if ((fromX == toX) || (fromY == toY)) //ensures they only move diagonally + { + Console.WriteLine("Your destination is illegal. You can only move diagonally."); + return; + } + //checkers can only move forward + if (((checkerToMove.color == "black") && (fromX <= toX)) || ((checkerToMove.color == "white") && (fromX >= toX))) + { + Console.WriteLine("Sorry, you can only move forward diagonally, not back."); + return; + } + //JUMPING A PIECE!! + if ((grid[toX,toY] != null) && (SelectChecker(toX, toY).color != checkerToMove.color)) //ensuring space is not empty, and space has enemy checker in it + { + if ((grid[fromX + ((toX-fromX)*2), fromY + ((toY-fromY)*2)] == null)) // ensuring space past checker to jump is empty + { + System.Console.WriteLine("You just jumped a checker!"); + if (checkerToMove.color == "white") + { + whiteScore++; + } + else + { + blackScore++; + } + checkers.Remove(SelectChecker(toX, toY)); + grid[toX,toY] = null; + toX = fromX + ((toX-fromX)*2); + toY = fromY + ((toY-fromY)*2); + } + else + { + System.Console.WriteLine("Sorry, you tried to jump a checker, but there's nowhere for you to land."); + return; + } + } + //also let the same player go again if they take out a checker, so they can chain jumps, but they cant change checkers (not sure how to do this yet) + checkerToMove.position[0] = toX; + checkerToMove.position[1] = toY; + grid[fromX,fromY] = null; + SwitchPlayers(); + } + + + // foreach (Checker c in checkers) // this is just a console for troubleshooting to ensure that the coordinates of the checkers are really updating + // { + // Console.WriteLine(c.color + " checker at X " + c.xPos + " and Y " + c.yPos); + // } + } + + public void CallItADay(){ + System.Console.WriteLine("The current score is WHITE {0}, BLACK {1}", whiteScore, blackScore); + System.Console.WriteLine("Would you like to move again, or call it a day?"); + System.Console.WriteLine("Type \"m\" to move again, or \"c\" to call it a day. No backsies."); + string input = Console.ReadLine(); + if (input.ToLower() == "m") { - Console.WriteLine("Your destination is out of bounds of the board"); return; } - //destination cant have another checker of the same color - if ((grid[toX,toY] != null) && (SelectChecker(toX, toY).color == checkerToMove.color)) //CHECKS IF DESTINATION HAS A CHECKER OF THE SAME COLOR + else if (input.ToLower() == "c") { - Console.WriteLine("You aren't allowed to land on another checker of your color"); - return; + System.Console.WriteLine("Final Score: WHITE {0} BLACK {1}", whiteScore, blackScore); + if (whiteScore > blackScore) + { + System.Console.WriteLine("White wins!"); + hasWon = true; + } + else if (whiteScore < blackScore) + { + System.Console.WriteLine("Black wins!"); + hasWon = true; + } + else if (whiteScore == blackScore) + { + System.Console.WriteLine("It's a tie! Incredible!"); + hasWon = true; + } } - //blacks can only move y-1 and either x-1 or x+1 - if (Math.Abs(fromY - toY) > 1 || Math.Abs(fromX - toX) > 1) + else { - Console.WriteLine("Your destination is illegal. You can only move diagonally 1 space. If you want to jump an enemy checker, choose it's location."); - return; + System.Console.WriteLine("Your input is invalid, my dude."); + CallItADay(); } - //whites can only move y+1 and either x-1 or x+1 - - // if opposite colored checker is in location where you want to jump, double the move (if its x+1 and y+1 do x+2 and y+2) - //also let the same player go again if they take out a checker, so they can chain jumps, but they cant change checkers (not sure how to do this yet) - checkerToMove.position[0] = toX; - checkerToMove.position[1] = toY; - - grid[fromX,fromY] = null; - - // foreach (Checker c in checkers) // this is just a console for troubleshooting to ensure that the coordinates of the checkers are really updating - // { - // Console.WriteLine(c.color + " checker at X " + c.xPos + " and Y " + c.yPos); - // } } public Checker SelectChecker(int row, int column) //selectchecker takes in x,y, returns checker or null, or throws exception @@ -178,16 +302,32 @@ public bool CheckForWin() return checkers.All(x => x.color == "white") || !checkers.Exists(x => x.color == "white"); } + public void WhoWon(){ + foreach (Checker c in checkers) + { + if (whiteScore == 12) + { + System.Console.WriteLine("White won! Wow! You actually played through a whole game!"); + } + else if (blackScore == 12) + { + System.Console.WriteLine("Black won! Incredible! I bet you wasted a lot of time to get here!"); + } + } + } + public void SwitchPlayers() { if (playerColor == "white") { - Console.WriteLine("White Turn"); + Console.WriteLine("Black Turn"); + System.Console.WriteLine("White score: {0} Black score: {1}", whiteScore, blackScore); playerColor = "black"; } else { - Console.WriteLine("Black Turn"); + Console.WriteLine("White Turn"); + System.Console.WriteLine("White score: {0} Black score: {1}", whiteScore, blackScore); playerColor = "white"; } } @@ -210,8 +350,10 @@ public Checker(bool isWhite, int xPos, int yPos) this.color = color; this.symbol = symbol; - int openCircleId = int.Parse("25CB", System.Globalization.NumberStyles.HexNumber); - int closedCircleId = int.Parse("25CF", System.Globalization.NumberStyles.HexNumber); + int openCircleId = int.Parse(" 25CE", System.Globalization.NumberStyles.HexNumber); + string openCircle = char.ConvertFromUtf32(openCircleId); + int closedCircleId = int.Parse(" 25C9", System.Globalization.NumberStyles.HexNumber); + string closedCircle = char.ConvertFromUtf32(closedCircleId); this.xPos = xPos; this.yPos = yPos; position[0] = xPos; @@ -220,18 +362,15 @@ public Checker(bool isWhite, int xPos, int yPos) if (isWhite) { color = "white"; - string openCircle = char.ConvertFromUtf32(openCircleId); // symbol = openCircle; symbol = "X"; } else { color = "black"; - string closedCircle = char.ConvertFromUtf32(closedCircleId); // symbol = closedCircle; symbol = "O"; } } } - } From 7273036ca0966e6521ff3c45dd80f29b625f769f Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Sun, 2 Sep 2018 15:19:24 -0500 Subject: [PATCH 7/8] still cleaning up checkers --- checkpoint2/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/checkpoint2/Program.cs b/checkpoint2/Program.cs index 03190ae3..0800464a 100644 --- a/checkpoint2/Program.cs +++ b/checkpoint2/Program.cs @@ -45,7 +45,6 @@ public Board() { this.checkers = new List(); } - //this is where we will need to build some methods to CreateBoard(board constructor), DrawBoard, GenerateBoard, SelectChecker, CheckValidMove(checkerposition[],tox,toy)RETURNBOOL, MoveChecker, RemoveChecker, and CheckForWin(take in color, did white win true false) public void DrawBoard() { From 6e104d449c3d09e264d20d28dd2e0734cc357d2a Mon Sep 17 00:00:00 2001 From: "James.Woodard" Date: Wed, 5 Sep 2018 18:44:05 -0500 Subject: [PATCH 8/8] i dont think anything has changed since the last commit but im just making sure --- checkpoint2/Program.cs | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/checkpoint2/Program.cs b/checkpoint2/Program.cs index 0800464a..4c717abb 100644 --- a/checkpoint2/Program.cs +++ b/checkpoint2/Program.cs @@ -11,7 +11,6 @@ static void Main(string[] args) Console.WriteLine("Checkerspoint 2. WHITE = X BLACK = O. WHITE GOES FIRST!"); Game myGame = new Game(); myGame.Start(); - } } public class Game @@ -20,8 +19,6 @@ public class Game public void Start() { Board aBoard = new Board(); - // Console.WriteLine(int.Parse("25CB", System.Globalization.NumberStyles.HexNumber)); - // Console.WriteLine(int.Parse("25CF", System.Globalization.NumberStyles.HexNumber)); aBoard.GenerateCheckers(); while (!aBoard.hasWon) { @@ -46,8 +43,7 @@ public Board() this.checkers = new List(); } public void DrawBoard() - { - + { Console.WriteLine(" 0 1 2 3 4 5 6 7 "); for (int i = 0; i < grid.GetLength(0); i++) { @@ -85,12 +81,10 @@ public void GenerateCheckers(){ // generate checkers only runs once at the begin } } } - // foreach (Checker c in checkers) //INTIAL CHECKER PLACEMENT CHECK // { // Console.WriteLine("Checker at X " + c.xPos + " and Y " + c.yPos); // } - } public void PlaceCheckers() //this is what reads the checker coordinates and puts it in the grid in the right place { @@ -102,19 +96,16 @@ public void PlaceCheckers() //this is what reads the checker coordinates and put return; } public void MoveChecker(){ - int[] validInput = new int[] {0,1,2,3,4,5,6,7}; int fromX = 0; int fromY = 0; int toX = 0; int toY = 0; string input = ""; - PlayerMove(); - void PlayerMove(){ GetPlayerInputFrom(); - // CheckPlayerInputFrom(); + // CheckPlayerInputFrom(); // i ended up daisy chaining these at the ends of each other to make it work the way i wanted it to // GetPlayerInputTo(); // CheckPlayerMove(); // SwitchPlayers(); @@ -128,7 +119,6 @@ void GetPlayerInputFrom(){ { CallItADay(); return; - } if(!Int32.TryParse(input, out fromX)) { @@ -145,8 +135,6 @@ void GetPlayerInputFrom(){ } CheckPlayerInputFrom(); } - - void CheckPlayerInputFrom(){ //INPUT CHECKS / FROM Checker checkerToMove = SelectChecker(fromX, fromY); @@ -167,7 +155,6 @@ void CheckPlayerInputFrom(){ } GetPlayerInputTo(); } - void GetPlayerInputTo(){ //GETTING PLAYER INPUT / TO Console.WriteLine("Enter Placement Row: "); @@ -186,7 +173,6 @@ void GetPlayerInputTo(){ } CheckPlayerMove(); } - void CheckPlayerMove(){ //MOVEMENT CHECKS / TO Checker checkerToMove = SelectChecker(fromX, fromY); @@ -241,20 +227,16 @@ void CheckPlayerMove(){ return; } } - //also let the same player go again if they take out a checker, so they can chain jumps, but they cant change checkers (not sure how to do this yet) checkerToMove.position[0] = toX; checkerToMove.position[1] = toY; grid[fromX,fromY] = null; SwitchPlayers(); } - - // foreach (Checker c in checkers) // this is just a console for troubleshooting to ensure that the coordinates of the checkers are really updating // { // Console.WriteLine(c.color + " checker at X " + c.xPos + " and Y " + c.yPos); // } } - public void CallItADay(){ System.Console.WriteLine("The current score is WHITE {0}, BLACK {1}", whiteScore, blackScore); System.Console.WriteLine("Would you like to move again, or call it a day?"); @@ -288,19 +270,15 @@ public void CallItADay(){ System.Console.WriteLine("Your input is invalid, my dude."); CallItADay(); } - } - public Checker SelectChecker(int row, int column) //selectchecker takes in x,y, returns checker or null, or throws exception { return checkers.Find(x => x.position.SequenceEqual(new List { row, column })); } - public bool CheckForWin() { return checkers.All(x => x.color == "white") || !checkers.Exists(x => x.color == "white"); } - public void WhoWon(){ foreach (Checker c in checkers) { @@ -314,7 +292,6 @@ public void WhoWon(){ } } } - public void SwitchPlayers() { if (playerColor == "white") @@ -330,9 +307,6 @@ public void SwitchPlayers() playerColor = "white"; } } - - - } public class Checker { @@ -346,7 +320,6 @@ public class Checker public Checker(bool isWhite, int xPos, int yPos) { - this.color = color; this.symbol = symbol; int openCircleId = int.Parse(" 25CE", System.Globalization.NumberStyles.HexNumber);