Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fb31233
100% working going to cleaan up the code from this point
Brettj85 Jan 19, 2019
4d645f0
finished tic tac toe, going to write it recursive and hopefully test …
Brettj85 Jan 19, 2019
1e25549
making recursive and test
Brettj85 Jan 19, 2019
9e92332
finished recursive play, score keeping, a basic AI. still to go... gi…
Brettj85 Jan 20, 2019
467d137
fixed some bugs with turn counting
Brettj85 Jan 20, 2019
620bc6c
attempting to give the AI some sort of direction. been slow going
Brettj85 Jan 20, 2019
5c5fab2
still working on AI, finished checks for win and working on checks fo…
Brettj85 Jan 20, 2019
81b8a89
finishing up medium dificulty, checking a diag potential victory has …
Brettj85 Jan 20, 2019
5c1bb8d
working code with 2 levels of AI and choices for which player or both…
Brettj85 Jan 21, 2019
6b71ec3
built main menu does not yet launch gameor check results
Brettj85 Jan 21, 2019
0574968
finished seperating the files
Brettj85 Jan 23, 2019
c4f870a
finished seperating the files
Brettj85 Jan 23, 2019
c346383
everything is seperated now working on getting it all together
Brettj85 Jan 25, 2019
5b8ff8e
moving to sorting
Brettj85 Jan 26, 2019
e98ad4c
finished tie function need to print out winner
Brettj85 Jan 28, 2019
74d693f
found issues all over the code ha ha this was done a couple weeks ago…
Brettj85 Jan 28, 2019
3e513f5
basicly rewrighting the whole thing 40 min before its due
Brettj85 Jan 28, 2019
6b346a4
its working at least
Brettj85 Jan 29, 2019
4a16946
not sure why its skipping the loop
Brettj85 Feb 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions TicTacToe/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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.0/TicTacToe.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
15 changes: 15 additions & 0 deletions TicTacToe/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/TicTacToe.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
196 changes: 144 additions & 52 deletions TicTacToe/TicTacToe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,84 +4,176 @@ namespace TicTacToe
{
class Program
{
public static string playerTurn = "X";
public static string[][] board = new string[][]
{
new string[] {" ", " ", " "},
new string[] {" ", " ", " "},
new string[] {" ", " ", " "}
};

public static void Main()
{
do
{
DrawBoard();
GetInput();

} while (!CheckForWin() && !CheckForTie());

// leave this command at the end so your program does not close automatically
Console.ReadLine();
playGame();
}

public static void GetInput()
public static void playGame()
{
Console.WriteLine("Player " + playerTurn);
Console.WriteLine("Enter Row:");
int row = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Column:");
int column = int.Parse(Console.ReadLine());
string playerTurn = "X";
string isWinner = "n";
string[,] board = new string[3, 3];
bool win = false;
while (!win)
{
board = selectSpot(board, playerTurn);
playerTurn = (playerTurn == "X") ? "O" : "X";
isWinner = checkWin(board);
isWinner = checkTie(board);
win = checkResult(isWinner);
}
}

public static void PlaceMark(int row, int column)
public static bool checkResult(string winner)
{
// your code goes here
if (winner == "X" || winner == "O")
{
Console.WriteLine("The winner is {0}", winner);
return true;
}
else if (winner == "T")
{
Console.WriteLine("Its a Tie!");
return true;
}
else
{
return false;
}
}

public static bool CheckForWin()
public static string[,] selectSpot(string[,] board, string playerTurn)
{
// your code goes here
int row = 10;
int column = 10;
bool controller = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you name this controller?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would "quit" and then "while(!quit)" be better that's what Ive been doing lately?

while (controller)
{
printBoard(board);
Console.WriteLine("Player " + playerTurn);
Console.WriteLine("Enter Row:");
row = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter Column:");
column = Int32.Parse(Console.ReadLine());

if (isTaken(board, row, column))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only thing missing from this selectSpot method is making sure I don't enter values outside of [0,2]

{
Console.WriteLine("sorry that spot is taken");
}
else
{
controller = false;
}

}

board[row, column] = playerTurn;
return board;

return false;
}

public static bool CheckForTie()
public static bool isTaken(string[,] board, int row, int column)
{
// your code goes here

return false;
if (row != 10 || column != 10)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic values are fine for now, but try to avoid them. Imagine looking at this method in 6 months. Will you remember what a row==10 value means?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont remember what it means now .... good point.

{
if (String.IsNullOrEmpty(board[row, column]))
{
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
public static bool HorizontalWin()

public static string checkWin(string[,] board)
{
// your code goes here
string checkRows = checkHorizontal(board);
string checkColumns = checkVertical(board);
string checkCorner2Corner = checkDiagonal(board);
if (checkRows == "X" || checkColumns == "X" || checkCorner2Corner == "X")
{
return "X";
}
else if (checkRows == "O" || checkColumns == "O" || checkCorner2Corner == "O")
{
return "O";
}
else
{
return "n";
}
}

return false;
public static string checkHorizontal(string[,] board)
{
string isWinner = "n";
for (int i = 0; i <= 2; i++)
{
if (board[i, 0] == board[i, 1] && board[i, 0] == board[i, 2] && !String.IsNullOrEmpty(board[i, 0]))
{
isWinner = board[i, 0];
}
}
return isWinner;
}

public static bool VerticalWin()
public static string checkVertical(string[,] board)
{
// your code goes here
string isWinner = "n";
for (int i = 0; i <= 2; i++)
{
if (board[0, i] == board[1, i] && board[0, i] == board[2, i] && !String.IsNullOrEmpty(board[0, i]))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever solution

{
isWinner = board[0, i];
}
}
return isWinner;

return false;
}

public static bool DiagonalWin()
public static string checkDiagonal(string[,] board)
{
// your code goes here

return false;
string isWinner = "n";
if (board[0, 0] == board[1, 1] && board[0, 0] == board[2, 2] && !String.IsNullOrEmpty(board[0, 0]))
{
isWinner = board[0, 0];
}
else if (board[0, 2] == board[1, 1] && board[0, 2] == board[2, 0] && !String.IsNullOrEmpty(board[0, 2]))
{
isWinner = board[0, 2];
}
return isWinner;
}

public static void DrawBoard()
public static string checkTie(string[,] board)
{
string winner = checkWin(board);
if (winner == "n")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling you will really like Enum types when we get to them :-)

{
for (int i = 0; i < 3; i++)
{
if (String.IsNullOrEmpty(board[i, 0]) || String.IsNullOrEmpty(board[i, 1]) || String.IsNullOrEmpty(board[i, 2]))
{
return "n";
}
}
return "t";
}
return winner;
}
public static void printBoard(string[,] board)
{
Console.WriteLine(" 0 1 2");
Console.WriteLine("0 " + String.Join("|", board[0]));
Console.WriteLine(" -----");
Console.WriteLine("1 " + String.Join("|", board[1]));
Console.WriteLine(" -----");
Console.WriteLine("2 " + String.Join("|", board[2]));
Console.WriteLine(" " + "0" + " 1 " + "2");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your board formatting is not as good as the original. Do you know what you are doing different from the original printBoard method that is causing you board to squish up?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the original. I fixed this in the Keep Score one and forgot to bring those changes back.

Console.WriteLine("0 " + board[0, 0] + "|" + board[0, 1] + "|" + board[0, 2]);
Console.WriteLine(" " + "-----");
Console.WriteLine("1 " + board[1, 0] + "|" + board[1, 1] + "|" + board[1, 2]);
Console.WriteLine(" " + "-----");
Console.WriteLine("2 " + board[2, 0] + "|" + board[2, 1] + "|" + board[2, 2]);
}
}
}
28 changes: 28 additions & 0 deletions keepScoreTicTT/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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.2/keepScoreTicTT.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": "integratedTerminal",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
]
}
15 changes: 15 additions & 0 deletions keepScoreTicTT/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/keepScoreTicTT.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
Loading