Started Assignment 3
This commit is contained in:
parent
ad3dd35a29
commit
2950468b65
11 changed files with 422 additions and 0 deletions
|
@ -14,12 +14,19 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
|
||||
testCompile("org.junit.jupiter:junit-jupiter-api:5.4.2")
|
||||
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.2")
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
tasks.named<Test>("test") {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.register<JavaExec>("Assignment4") {
|
||||
classpath = sourceSets.main.get().runtimeClasspath
|
||||
main = "com.anthonycicchetti.cs5004.assignment4.Main"
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.anthonycicchetti.cs5004.assignment3
|
||||
|
||||
import com.anthonycicchetti.cs5004.assignment3.pieces.IChessPiece
|
||||
|
||||
class Board() {
|
||||
enum class Column {
|
||||
A, B, C, D, E, F, G
|
||||
}
|
||||
|
||||
enum class Row {
|
||||
ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT
|
||||
}
|
||||
data class BoardSquare(val location: BoardLocation, var piece: IChessPiece?)
|
||||
data class BoardLocation(val column: Column, val row: Row)
|
||||
|
||||
val state: List<BoardSquare>
|
||||
|
||||
init {
|
||||
val initialState = mutableListOf<BoardSquare>()
|
||||
for (column in Column.values()) {
|
||||
for (row in Row.values())
|
||||
initialState.add(BoardSquare(BoardLocation(column, row), null))
|
||||
}
|
||||
state = initialState
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.anthonycicchetti.cs5004.assignment3
|
||||
|
||||
object Main {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
println("Hello world")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.anthonycicchetti.cs5004.assignment3.pieces
|
||||
|
||||
import com.anthonycicchetti.cs5004.assignment3.Board
|
||||
|
||||
interface IChessPiece {
|
||||
fun getPosition(): Board.BoardLocation
|
||||
fun getColor(): Color
|
||||
fun canMoveTo(square: Board.BoardLocation): Boolean
|
||||
fun canKill(enemyPiece: IChessPiece): Boolean
|
||||
fun moveTo(square: Board.BoardLocation): Boolean
|
||||
}
|
||||
|
||||
enum class Color {
|
||||
WHITE, BLACK
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
package com.anthonycicchetti.cs5004.assignment3.pieces
|
||||
|
||||
import com.anthonycicchetti.cs5004.assignment3.Board
|
||||
|
||||
sealed class Piece: IChessPiece
|
||||
|
||||
data class Bishop(var location: Board.BoardLocation, private val color: Color): Piece() {
|
||||
override fun moveTo(square: Board.BoardLocation): Boolean {
|
||||
if (canMoveTo(location)) {
|
||||
this.location = square
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getPosition(): Board.BoardLocation {
|
||||
return location
|
||||
}
|
||||
|
||||
override fun getColor(): Color {
|
||||
return color
|
||||
}
|
||||
|
||||
override fun canMoveTo(square: Board.BoardLocation): Boolean {
|
||||
TODO()
|
||||
}
|
||||
|
||||
override fun canKill(enemyPiece: IChessPiece): Boolean {
|
||||
return canMoveTo(enemyPiece.getPosition())
|
||||
}
|
||||
}
|
||||
|
||||
data class Knight(var location: Board.BoardLocation, private val color: Color): Piece() {
|
||||
override fun moveTo(square: Board.BoardLocation): Boolean {
|
||||
if (canMoveTo(location)) {
|
||||
this.location = square
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getPosition(): Board.BoardLocation {
|
||||
return location
|
||||
}
|
||||
|
||||
override fun getColor(): Color {
|
||||
return color
|
||||
}
|
||||
|
||||
override fun canMoveTo(square: Board.BoardLocation): Boolean {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun canKill(enemyPiece: IChessPiece): Boolean {
|
||||
return canMoveTo(enemyPiece.getPosition())
|
||||
}
|
||||
}
|
||||
|
||||
data class Rook(var location: Board.BoardLocation, private val color: Color): Piece() {
|
||||
override fun moveTo(square: Board.BoardLocation): Boolean {
|
||||
if (canMoveTo(location)) {
|
||||
this.location = square
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getPosition(): Board.BoardLocation {
|
||||
return location
|
||||
}
|
||||
|
||||
override fun getColor(): Color {
|
||||
return color
|
||||
}
|
||||
|
||||
override fun canMoveTo(square: Board.BoardLocation): Boolean {
|
||||
return with(square) {
|
||||
this.column == this@Rook.location.column ||
|
||||
this.row == this@Rook.location.row
|
||||
}
|
||||
}
|
||||
|
||||
override fun canKill(enemyPiece: IChessPiece): Boolean {
|
||||
return canMoveTo(enemyPiece.getPosition())
|
||||
}
|
||||
}
|
||||
|
||||
data class Queen(var location: Board.BoardLocation, private val color: Color): Piece() {
|
||||
override fun moveTo(square: Board.BoardLocation): Boolean {
|
||||
if (canMoveTo(location)) {
|
||||
this.location = square
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getPosition(): Board.BoardLocation {
|
||||
return location
|
||||
}
|
||||
|
||||
override fun getColor(): Color {
|
||||
return color
|
||||
}
|
||||
|
||||
override fun canMoveTo(square: Board.BoardLocation): Boolean {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun canKill(enemyPiece: IChessPiece): Boolean {
|
||||
return canMoveTo(enemyPiece.getPosition())
|
||||
}
|
||||
}
|
||||
|
||||
data class King(var location: Board.BoardLocation, private val color: Color): Piece() {
|
||||
override fun moveTo(square: Board.BoardLocation): Boolean {
|
||||
if (canMoveTo(location)) {
|
||||
this.location = square
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getPosition(): Board.BoardLocation {
|
||||
return location
|
||||
}
|
||||
|
||||
override fun getColor(): Color {
|
||||
return color
|
||||
}
|
||||
|
||||
override fun canMoveTo(square: Board.BoardLocation): Boolean {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun canKill(enemyPiece: IChessPiece): Boolean {
|
||||
return canMoveTo(enemyPiece.getPosition())
|
||||
}
|
||||
}
|
||||
|
||||
data class Pawn(var location: Board.BoardLocation, private val color: Color): Piece() {
|
||||
override fun moveTo(square: Board.BoardLocation): Boolean {
|
||||
if (canMoveTo(location)) {
|
||||
this.location = square
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getPosition(): Board.BoardLocation {
|
||||
return location
|
||||
}
|
||||
|
||||
override fun getColor(): Color {
|
||||
return color
|
||||
}
|
||||
|
||||
override fun canMoveTo(square: Board.BoardLocation): Boolean {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun canKill(enemyPiece: IChessPiece): Boolean {
|
||||
return canMoveTo(enemyPiece.getPosition())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.anthonycicchetti.cs5004.assignment3.pieces
|
||||
|
||||
import com.anthonycicchetti.cs5004.assignment3.Board
|
||||
import com.sun.source.tree.WhileLoopTree
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
|
||||
internal class BishopTest {
|
||||
|
||||
val A_ONE = Board.BoardLocation(Board.Column.A, Board.Row.ONE)
|
||||
val D_FOUR = Board.BoardLocation(Board.Column.D, Board.Row.FOUR)
|
||||
|
||||
@Test
|
||||
fun getPosition() {
|
||||
val expected = Bishop(A_ONE, Color.WHITE)
|
||||
val actual = Bishop(Board.BoardLocation(Board.Column.A, Board.Row.ONE), Color.WHITE)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Can Move One Space Up-Right`() {
|
||||
val bishop = Bishop(A_ONE, Color.WHITE)
|
||||
assertTrue(bishop.canMoveTo(Board.BoardLocation(Board.Column.B, Board.Row.TWO)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Can Move Four Spaces Up-Right`() {
|
||||
val bishop = Bishop(A_ONE, Color.WHITE)
|
||||
assertTrue(bishop.canMoveTo(Board.BoardLocation(Board.Column.D, Board.Row.FOUR)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Cannot Move One Space Right`() {
|
||||
val bishop = Bishop(A_ONE, Color.WHITE)
|
||||
assertFalse(bishop.canMoveTo(Board.BoardLocation(Board.Column.B, Board.Row.ONE)))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.anthonycicchetti.cs5004.assignment3.pieces
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
|
||||
internal class KingTest {
|
||||
|
||||
@Test
|
||||
fun getPosition() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getColor() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun canMoveTo() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun canKill() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.anthonycicchetti.cs5004.assignment3.pieces
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
|
||||
internal class KnightTest {
|
||||
|
||||
@Test
|
||||
fun getPosition() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getColor() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun canMoveTo() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun canKill() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.anthonycicchetti.cs5004.assignment3.pieces
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
|
||||
internal class PawnTest {
|
||||
|
||||
@Test
|
||||
fun getPosition() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getColor() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun canMoveTo() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun canKill() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.anthonycicchetti.cs5004.assignment3.pieces
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
|
||||
internal class QueenTest {
|
||||
|
||||
@Test
|
||||
fun getPosition() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getColor() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun canMoveTo() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun canKill() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.anthonycicchetti.cs5004.assignment3.pieces
|
||||
|
||||
import com.anthonycicchetti.cs5004.assignment3.Board
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
|
||||
internal class RookTest {
|
||||
|
||||
val A_ONE = Board.BoardLocation(Board.Column.A, Board.Row.ONE)
|
||||
val D_FOUR = Board.BoardLocation(Board.Column.D, Board.Row.FOUR)
|
||||
|
||||
@Test
|
||||
fun `Can Move One Space to the Right`() {
|
||||
val rook = Rook(A_ONE, Color.WHITE)
|
||||
|
||||
assertTrue(rook.canMoveTo(Board.BoardLocation(Board.Column.B, Board.Row.ONE)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Can Move Four Spaces to the Right`() {
|
||||
val rook = Rook(A_ONE, Color.WHITE)
|
||||
|
||||
assertTrue(rook.canMoveTo(Board.BoardLocation(Board.Column.E, Board.Row.ONE)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Can Move One Space to the Left`() {
|
||||
val rook = Rook(D_FOUR, Color.WHITE)
|
||||
|
||||
assertTrue(rook.canMoveTo(Board.BoardLocation(Board.Column.C, Board.Row.FOUR)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Can Move Three Spaces to the Left`() {
|
||||
val rook = Rook(D_FOUR, Color.WHITE)
|
||||
|
||||
assertTrue(rook.canMoveTo(Board.BoardLocation(Board.Column.A, Board.Row.FOUR)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Can Move One Space Up`() {
|
||||
val rook = Rook(A_ONE, Color.WHITE)
|
||||
|
||||
assertTrue(rook.canMoveTo(Board.BoardLocation(Board.Column.A, Board.Row.TWO)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Can Move Five Spaces Up`() {
|
||||
val rook = Rook(A_ONE, Color.WHITE)
|
||||
|
||||
assertTrue(rook.canMoveTo(Board.BoardLocation(Board.Column.A, Board.Row.FIVE)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Can Move One Space Down`() {
|
||||
val rook = Rook(D_FOUR, Color.WHITE)
|
||||
|
||||
assertTrue(rook.canMoveTo(Board.BoardLocation(Board.Column.D, Board.Row.THREE)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Can Move Two Spaces Down`() {
|
||||
val rook = Rook(D_FOUR, Color.WHITE)
|
||||
|
||||
assertTrue(rook.canMoveTo(Board.BoardLocation(Board.Column.D, Board.Row.TWO)))
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue