Skip to content

Terminal Game. Black and White have only pawns. White wins if their pawn moved to 8th line. Black wins if their pawn moves to 1st line. If black or white haven't any move, then no one wins(stalemate))

LP110108/Chess-Only-Pawns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Only-Pawns-Chess

Terminal game for 2 players
Regular chess but all sides have only pawns

Rules

This game extend all the rules of regular chess but it has one more rule:

  • If pawn of some side is on last line, then that side is winner!

Snippets of code

This class is used for count pawns on the board

 enum class Pawns(val color: String, var left: Int) {
    WHITE("White", 8),
    BLACK("Black", 8);

    fun beat() {
        left--
    }
 }
 

This snippet of code used to create board

val boldLine = "  +---+---+---+---+---+---+---+---+"
val filesLine = "    a   b   c   d   e   f   g   h"
val files = "abcdefgh"
val regex = """[a-h][1-8][a-h][1-8]\b""".toRegex()
val blackPlayer = "| B "
val whitePlayer = "| W "
var chosenPlayer = whitePlayer
val emptySlot = "|   "
val blackPlayerStartingIndex = 7
val whitePlayerStartingIndex = 2
var invalidInput = false
var whitePassant = false
var blackPassant = false
var currentCoords = ""
//chessboard initialization
val chessboard = mutableListOf(
    MutableList(8) { "|   " }, //8
    MutableList(8) { blackPlayer },//7
    MutableList(8) { "|   " }, //6
    MutableList(8) { "|   " }, //5
    MutableList(8) { "|   " }, //4
    MutableList(8) { "|   " }, //3
    MutableList(8) { whitePlayer }, //2
    MutableList(8) { "|   " } //1
).reversed()

This is start of the game

println(" Pawns-Only Chess")
println("First Player's name: ")
val player1 = readLine()!!
println("Second Player's name: ")
val player2 = readLine()!!
var currentTurn = player1

This is printing result of the game

fun ending(res: String) {
    printBoard()
    when (res) {
        "P1" -> {
            currentTurn = "exit"
            println("White wins!")
            println("Bye!")
        }
        "P2" -> {
            currentTurn = "exit"
            println("Black wins!")
            println("Bye!")
        }
        else -> {
            currentTurn = "exit"
            println("Stalemate!")
            println("Bye!")
        }
    }
}

About

Terminal Game. Black and White have only pawns. White wins if their pawn moved to 8th line. Black wins if their pawn moves to 1st line. If black or white haven't any move, then no one wins(stalemate))

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages