From a22e0336e9bf8cc96452eafc4f5bf8ce69de4418 Mon Sep 17 00:00:00 2001 From: vr-ski Date: Wed, 10 Apr 2024 23:42:45 +0300 Subject: [PATCH 1/5] first draft: first commit --- src/game.java | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/game.java diff --git a/src/game.java b/src/game.java new file mode 100644 index 0000000..4a9019e --- /dev/null +++ b/src/game.java @@ -0,0 +1,41 @@ +public class Game { + + private int size; + private int[size][size] grid; + + public Game(int newSize) { + size = newSize + } + + private boolean registerMove(int x, int y, Player player) { + + boolean successful_outcome = false; + + if grid[x][y] == "empty" { + grid[x][y] = player.getSymbol() + successful_outcome = true; + } + + return successful_outcome; + + } + + private boolean confirmWin(Player player) { + + // check if player wins + return + } + + private boolean confirmEndOfGame() { + + // check end of game + return + } + + public void playerTurn(int x, int y, Player player) { + + // call private methods + + } + +} From fefddd7912f75b4268ce74fc1f6b4bbd161f2738 Mon Sep 17 00:00:00 2001 From: vr-ski Date: Wed, 17 Apr 2024 00:24:08 +0300 Subject: [PATCH 2/5] first draft: dynamically initialize grid --- src/game.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/game.java b/src/game.java index 4a9019e..319cbd5 100644 --- a/src/game.java +++ b/src/game.java @@ -1,10 +1,11 @@ public class Game { private int size; - private int[size][size] grid; + private int[][] grid; public Game(int newSize) { - size = newSize + size = newSize; + grid = new int[size][size]; } private boolean registerMove(int x, int y, Player player) { From a20cc8ca0a406f1cd71c76ae836578ed38723e7b Mon Sep 17 00:00:00 2001 From: vr-ski Date: Wed, 17 Apr 2024 00:25:25 +0300 Subject: [PATCH 3/5] first draft: use this for better readability --- src/game.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game.java b/src/game.java index 319cbd5..b6d0df5 100644 --- a/src/game.java +++ b/src/game.java @@ -4,8 +4,8 @@ public class Game { private int[][] grid; public Game(int newSize) { - size = newSize; - grid = new int[size][size]; + this.size = newSize; + grid = new int[this.size][this.size]; } private boolean registerMove(int x, int y, Player player) { From ea3f73705ce624c875e508c38a19f1d72a773f9f Mon Sep 17 00:00:00 2001 From: vr-ski Date: Wed, 17 Apr 2024 22:31:58 +0300 Subject: [PATCH 4/5] first draft: use camelCase for variables and other small fixed; first part of win check --- src/game.java | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/game.java b/src/game.java index b6d0df5..525f52d 100644 --- a/src/game.java +++ b/src/game.java @@ -1,5 +1,6 @@ public class Game { + private static final int EMPTY = 0; private int size; private int[][] grid; @@ -8,32 +9,42 @@ public Game(int newSize) { grid = new int[this.size][this.size]; } - private boolean registerMove(int x, int y, Player player) { + private boolean registerMove(int x, int y, int player) { - boolean successful_outcome = false; + boolean successfulOutcome = false; - if grid[x][y] == "empty" { + if (grid[x][y] == EMPTY) { grid[x][y] = player.getSymbol() - successful_outcome = true; + successfulOutcome = true; } - return successful_outcome; + return successfulOutcome; } - private boolean confirmWin(Player player) { + private boolean confirmWin(int player) { // check if player wins - return + playerWon = false; + + if (this.grid[0][0] == player) { + if (this.grid[0][1] == player) { + if (this.grid[0][2] == player) { + playerWon = true; + } + } + } + + return playerWon; } private boolean confirmEndOfGame() { - // check end of game + // check end of game return } - public void playerTurn(int x, int y, Player player) { + public void playerTurn(int x, int y, int player) { // call private methods From c71b61f1d8ae0c12bc153a7e0cdf3c822e56b92c Mon Sep 17 00:00:00 2001 From: vr-ski Date: Sat, 27 Apr 2024 12:11:24 +0300 Subject: [PATCH 5/5] first draft: use byte instead of int, since its enough for the purposes --- src/game.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/game.java b/src/game.java index 525f52d..b461a50 100644 --- a/src/game.java +++ b/src/game.java @@ -1,15 +1,15 @@ public class Game { private static final int EMPTY = 0; - private int size; - private int[][] grid; + private byte size; + private byte[][] grid; public Game(int newSize) { this.size = newSize; - grid = new int[this.size][this.size]; + grid = new byte[this.size][this.size]; } - private boolean registerMove(int x, int y, int player) { + private boolean registerMove(byte x, byte y, byte player) { boolean successfulOutcome = false; @@ -22,7 +22,7 @@ private boolean registerMove(int x, int y, int player) { } - private boolean confirmWin(int player) { + private boolean confirmWin(byte player) { // check if player wins playerWon = false; @@ -44,7 +44,7 @@ private boolean confirmEndOfGame() { return } - public void playerTurn(int x, int y, int player) { + public void playerTurn(byte x, byte y, byte player) { // call private methods