Skip to content

Commit 607a7f7

Browse files
dzianis-sudkoudzianis-sudkou
authored andcommitted
Finished work on the Computer Alghorithm
1 parent b32fd81 commit 607a7f7

File tree

3 files changed

+31
-48
lines changed

3 files changed

+31
-48
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.words": [
3+
"println"
4+
]
5+
}

src/Stupid.effekt

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import src/Render
88
import src/Generate
99

1010

11-
1211
def playGame(): Unit = {
1312

1413
// Returns the chosen Game Mode
@@ -81,6 +80,7 @@ def playGame(): Unit = {
8180
}
8281
}
8382

83+
// Core Game Loop
8484
def gameLoop(player: Cell, gameMode: GameMode): Unit / {WrongInput} = {
8585
var endGame: Bool = false
8686

@@ -95,28 +95,10 @@ def playGame(): Unit = {
9595

9696
printGameScreen(gameBoard, player)
9797

98-
// if (player is Cross()) {
99-
// println("You're starting the game!\nChoose the starting Small Board.")
100-
// currentSmallBoard = chooseSmallBoard(gameBoard)
101-
// gameBoard = newActiveSmallBoard(gameBoard, currentSmallBoard)
102-
// } else {
103-
// println("Opponent is starting the game!\n")
104-
// if (gameMode is Computer()){
105-
// currentSmallBoard = computerPlay(gameBoard.smallCopy, computer)
106-
// gameBoard = newActiveSmallBoard(gameBoard, currentSmallBoard)
107-
// }else{
108-
// currentSmallBoard = chooseSmallBoard(gameBoard)
109-
// gameBoard = newActiveSmallBoard(gameBoard, currentSmallBoard)
110-
// }
111-
// }
112-
println("You're starting the game!\nChoose the starting Small Board.")
113-
currentSmallBoard = chooseSmallBoard(gameBoard)
114-
gameBoard = newActiveSmallBoard(gameBoard, currentSmallBoard)
98+
println(playerString(currentPlayer) ++ " - You're starting the game!\nChoose the starting Small Board.")
11599

116100
// INNER GAME LOOP OF ONE GAME
117101
while (not(endGame)){
118-
119-
120102
// Choose the new Small Board
121103
if (currentSmallBoard == 10) {
122104
if (gameMode is Computer()) {
@@ -167,11 +149,6 @@ def playGame(): Unit = {
167149
currentCell = 10
168150

169151
// Verify if the game has been won
170-
if (checkWinSituation(gameBoard.smallCopy, currentPlayer) is Win()){
171-
println(playerString(currentPlayer) ++ ", You won the game!")
172-
consoleInput()
173-
endGame = true
174-
}
175152

176153
checkWinSituation(gameBoard.smallCopy, currentPlayer) match {
177154
case Win() => {
@@ -189,6 +166,8 @@ def playGame(): Unit = {
189166
// Change The Current Player
190167
if(currentPlayer is Cross()) currentPlayer = Nought()
191168
else currentPlayer = Cross()
169+
170+
printGameScreen(gameBoard, currentPlayer)
192171
()
193172
}
194173
}

src/lib.effekt

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,29 @@ def playerString(player: Cell): String = {
4343
}
4444
}
4545

46-
/*
47-
* Compares two lists and gives true if they're the same
48-
* Input: list1, list2
49-
* Output: Bool
50-
*/
51-
def compare(list1: List[Int], list2: List[Int]): Bool = {
52-
with on[OutOfBounds].panic
46+
// /*
47+
// * Compares two lists and gives true if they're the same
48+
// * Input: list1, list2
49+
// * Output: Bool
50+
// */
51+
// def compare(list1: List[Int], list2: List[Int]): Bool = {
52+
// with on[OutOfBounds].panic
5353

54-
55-
if ((list1.size == list2.size) && not(list1.size == 0)){
56-
var counter: Int = 0
57-
var output: Bool = true
58-
while (counter < list1.size && output){
59-
if(list1.get(counter) == list2.get(counter)){
60-
counter = counter + 1
61-
} else {
62-
output = false
63-
}
64-
}
65-
output
66-
}else{
67-
false
68-
}
69-
}
54+
// if ((list1.size == list2.size) && not(list1.size == 0)){
55+
// var counter: Int = 0
56+
// var output: Bool = true
57+
// while (counter < list1.size && output){
58+
// if(list1.get(counter) == list2.get(counter)){
59+
// counter = counter + 1
60+
// } else {
61+
// output = false
62+
// }
63+
// }
64+
// output
65+
// }else{
66+
// false
67+
// }
68+
// }
7069

7170
def consoleInput(): String = {
7271
with console

0 commit comments

Comments
 (0)