All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netsensia.rivalchess.model.helper.SliderDirection.kt Maven / Gradle / Ivy

The newest version!
package com.netsensia.rivalchess.model.helper

import com.netsensia.rivalchess.model.Piece
import com.netsensia.rivalchess.model.exception.MoveGenerationException
import java.util.*

enum class SliderDirection(val xIncrement: Int, val yIncrement: Int) {
    N(0, -1),
    NE(1, -1),
    E(1, 0),
    SE(1, 1),
    S(0, 1),
    SW(-1, 1),
    W(-1, 0),
    NW(-1, -1);

    companion object {
        private val queenDirections: List = ArrayList(listOf(NE, NW, SE, SW, N, W, S, E))
        private val rookDirections: List = ArrayList(listOf(N, W, S, E))
        private val bishopDirections: List = ArrayList(listOf(NE, NW, SE, SW))

        fun getDirectionsForPiece(piece: Piece): List {
            return when (piece) {
                Piece.KING, Piece.QUEEN -> queenDirections
                Piece.BISHOP -> bishopDirections
                Piece.ROOK -> rookDirections
                else -> throw MoveGenerationException("Can't get directions for a non-sliding piece")
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy