From ee141149f7fde96c28d44c3decdbc5f0267aba23 Mon Sep 17 00:00:00 2001 From: masykur Date: Sat, 26 Feb 2022 08:47:53 +0700 Subject: [PATCH 1/3] Bug fix of C# logic and ignore .vscode/ folder --- .gitignore | 1 + 89_Tic-Tac-Toe/csharp/tictactoe1/Program.cs | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index d2115efc..f23bcbe8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.class */.vs *.suo +.vscode/ bin/ obj/ diff --git a/89_Tic-Tac-Toe/csharp/tictactoe1/Program.cs b/89_Tic-Tac-Toe/csharp/tictactoe1/Program.cs index 58f7d36f..d4955a40 100644 --- a/89_Tic-Tac-Toe/csharp/tictactoe1/Program.cs +++ b/89_Tic-Tac-Toe/csharp/tictactoe1/Program.cs @@ -33,13 +33,15 @@ while(true) { d = move(c + 3); computerMoves(d); s = readYourMove(); - if (s != move(d + 4)) { + if (s == move(d + 4)) { + e = move(d + 6); + computerMoves(e); + Console.WriteLine("THE GAME IS A DRAW."); + } else { e = move(d + 4); computerMoves(e); + Console.WriteLine("AND WINS ********"); } - e = move(d + 6); - computerMoves(e); - Console.WriteLine("THE GAME IS A DRAW."); } else { d = move(c + 7); computerMoves(d); From 744bafebf1d828931308768b3a56afbf04caab4d Mon Sep 17 00:00:00 2001 From: masykur Date: Sat, 26 Feb 2022 09:54:21 +0700 Subject: [PATCH 2/3] Added tictactoe1 in Golang --- .gitignore | 1 - 89_Tic-Tac-Toe/go/src/tictactoe1.go | 88 +++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 89_Tic-Tac-Toe/go/src/tictactoe1.go diff --git a/.gitignore b/.gitignore index 43cfcf3f..2675262f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ buildJvm/*/build/ *.class */.vs *.suo -.vscode/ bin/ obj/ diff --git a/89_Tic-Tac-Toe/go/src/tictactoe1.go b/89_Tic-Tac-Toe/go/src/tictactoe1.go new file mode 100644 index 00000000..a6dcbb69 --- /dev/null +++ b/89_Tic-Tac-Toe/go/src/tictactoe1.go @@ -0,0 +1,88 @@ +package main + +import ( + "fmt" + "strconv" +) + +func main() { + fmt.Printf("Hello, World!\n") + // Print text on the screen with 30 spaces before text + fmt.Printf("%30s\n", "TIC TAC TOE") + // Print text on screen with 15 spaces before text + // And print three lines break on screen + fmt.Printf("%15s\n\n\n\n", "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY") + // THIS PROGRAM PLAYS TIC TAC TOE + // THE MACHINE GOES FIRST + fmt.Printf("THE GAME BOARD IS NUMBERED:\n\n") + fmt.Println("1 2 3") + fmt.Println("8 9 4") + fmt.Println("7 6 5") + + // Main program + for { + var ( + a, b, c, d, e int + p, q, r, s int + ) + a = 9 + fmt.Printf("\n\n") + computerMoves(a) + p = readYourMove() + b = move(p + 1) + computerMoves(b) + q = readYourMove() + if q == move(b+4) { + c = move(b + 2) + computerMoves(c) + r = readYourMove() + if r == move(c+4) { + if p%2 != 0 { + d = move(c + 3) + computerMoves(d) + s = readYourMove() + if s == move(d+4) { + e = move(d + 6) + computerMoves(e) + fmt.Println("THE GAME IS A DRAW.") + } else { + e = move(d + 4) + computerMoves(e) + fmt.Println("AND WINS ********") + } + } else { + d = move(c + 7) + computerMoves(d) + fmt.Println("AND WINS ********") + } + } else { + d = move(c + 4) + computerMoves(d) + fmt.Println("AND WINS ********") + } + } else { + c = move(b + 4) + computerMoves(c) + fmt.Println("AND WINS ********") + } + } +} +func computerMoves(move int) { + fmt.Printf("COMPUTER MOVES %v\n", move) +} + +func readYourMove() int { + for { + fmt.Printf("YOUR MOVE?") + var input string + fmt.Scan(&input) + number, err := strconv.Atoi(input) + if err == nil { + return number + } + } +} + +func move(number int) int { + return number - 8*(int)((number-1)/8) +} From 1e082e8650965eec210284f3a8b3511b4fba0373 Mon Sep 17 00:00:00 2001 From: masykur Date: Sat, 26 Feb 2022 11:32:49 +0700 Subject: [PATCH 3/3] Added tictactoe1 in Pascal --- 89_Tic-Tac-Toe/go/README.md | 3 + 89_Tic-Tac-Toe/pascal/tictactoe1.pas | 103 +++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 89_Tic-Tac-Toe/go/README.md create mode 100644 89_Tic-Tac-Toe/pascal/tictactoe1.pas diff --git a/89_Tic-Tac-Toe/go/README.md b/89_Tic-Tac-Toe/go/README.md new file mode 100644 index 00000000..aa1b3ae5 --- /dev/null +++ b/89_Tic-Tac-Toe/go/README.md @@ -0,0 +1,3 @@ +Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html) + +Conversion to [Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language)) diff --git a/89_Tic-Tac-Toe/pascal/tictactoe1.pas b/89_Tic-Tac-Toe/pascal/tictactoe1.pas new file mode 100644 index 00000000..2329ce79 --- /dev/null +++ b/89_Tic-Tac-Toe/pascal/tictactoe1.pas @@ -0,0 +1,103 @@ +program tictactoe1; +var + a, b, c, d, e: integer; + p, q, r, s: integer; +procedure computerMoves(m: integer); +begin + write('COMPUTER MOVES '); + writeln(m); +end; + +function readYourMove() : integer; +var number: integer; +begin + write('YOUR MOVE?'); + readln(number); + readYourMove := number; +end; + +function move(number: integer): integer; +begin + move := number - 8 * trunc((number - 1) / 8); +end; + +function padLeft(m: string; n: integer): string; +var tmp: string; +begin + tmp := ''; + repeat + tmp := tmp + ' '; + n := n - 1; + until n = 0; + tmp := tmp + m; + padLeft := tmp; +end; + +begin + writeln(padLeft('TIC TAC TOE', 30)); + writeln(padLeft('CREATIVE COMPUTING MORRISTOWN, NEW JERSEY', 15)); + writeln(''); + writeln(''); + writeln(''); + writeln('THE GAME BOARD IS NUMBERED:'); + writeln(''); + writeln('1 2 3'); + writeln('8 9 4'); + writeln('7 6 5'); + while(true) do + begin + writeln(''); + writeln(''); + a := 9; + computerMoves(a); + p := readYourMove(); + b := move(p + 1); + computerMoves(b); + q := readYourMove(); + if (q = move(b + 4)) then + begin + c := move(b + 2); + computerMoves(c); + r := readYourMove(); + if (r = move(c + 4)) then + begin + if (p mod 2 <> 0) then + begin + d := move(c + 3); + computerMoves(d); + s := readYourMove(); + if (s = move(d + 4)) then + begin + e := move(d + 6); + computerMoves(e); + writeln('THE GAME IS A DRAW.'); + end + else + begin + e := move(d + 4); + computerMoves(e); + writeln('AND WINS ********'); + end + end + else + begin + d := move(c + 7); + computerMoves(d); + writeln('AND WINS ********'); + end + end + else + begin + d := move(c + 4); + computerMoves(d); + writeln('AND WINS ********'); + end + end + else + begin + c := move(b + 4); + computerMoves(c); + writeln('AND WINS ********'); + end; + end; +end. \ No newline at end of file