-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.kt
41 lines (33 loc) · 1017 Bytes
/
Main.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package chess
import Board
import java.util.Locale
fun main() {
val board = Board()
println(Board.title)
// Prompting players for their names
println("First Player's name:")
val player1Name = readlnOrNull() ?: ""
println("Second Player's name:")
val player2Name = readlnOrNull() ?: ""
// Main game loop
var currentPlayer = player1Name
var move: String
board.printBoard()
while (true) {
println("$currentPlayer's turn: ")
move = readlnOrNull() ?: ""
// Checking for the exit command
if (move.lowercase(Locale.getDefault()) == "exit") {
println("Bye!")
break
}
if (!board.isValidMove(move, currentPlayer == player1Name)) {
continue
}
board.movePawn(move)
board.printBoard()
if (board.checkGameOver()) break
// Switch to the other player's turn
currentPlayer = if (currentPlayer == player1Name) player2Name else player1Name
}
}