diff --git a/CheckersClient/core/src/com/mygdx/game/controllers/NetworkController.java b/CheckersClient/core/src/com/mygdx/game/controllers/NetworkController.java index 92da9b2b6c542d654861ae95958c972aa16a1b7a..3043914a972969c72d48230b5383ec64de0c7ebc 100644 --- a/CheckersClient/core/src/com/mygdx/game/controllers/NetworkController.java +++ b/CheckersClient/core/src/com/mygdx/game/controllers/NetworkController.java @@ -23,8 +23,10 @@ public class NetworkController { this.client = new Client(); client.start(); try { - String IP4_LAN_ADDRESS = "192.168.0.136"; //122 //"192.168.87.20"; - client.connect(10000, IP4_LAN_ADDRESS, 54555, 54777); + + String IP4_LAN_ADDRESS = "192.168.0.109"; + client.connect(10000, IP4_LAN_ADDRESS, 54555); + } catch (IOException e) { e.printStackTrace(); } diff --git a/CheckersClient/core/src/com/mygdx/game/model/GameMode.kt b/CheckersClient/core/src/com/mygdx/game/model/GameMode.kt index a9d3a5771e3b7d49ed006f0af12e34980ea40407..4e7308aebc14c1cb23feed2026320bd902d0cc38 100644 --- a/CheckersClient/core/src/com/mygdx/game/model/GameMode.kt +++ b/CheckersClient/core/src/com/mygdx/game/model/GameMode.kt @@ -47,7 +47,9 @@ class GameMode(rules:AbstractRules, board:AbstractBoard) { } private fun isPathJumpable(position: Vector3, direction: Vector3, destination: Vector3): Boolean { - var v = position.cpy().add(direction) + + val v = position.cpy().add(direction) + while (v != destination) { if (isFieldClear(v) || this.board?.fieldExists(v) == false) { return false @@ -60,28 +62,11 @@ class GameMode(rules:AbstractRules, board:AbstractBoard) { return false } - private fun getSecondaryJumpDirection(direction: Vector3): Vector3 { - var v = Vector3(0f,0f,0f) - when (direction) { - Vector3(-1f, 1f, 0f) -> v = Vector3(0f, -1f, 1f) - Vector3(1f, -1f, 0f) -> v = Vector3(-1f, 0f, 1f) - Vector3(0f, -1f, 1f) -> v = Vector3(1f, 0f, -1f) - Vector3(0f, 1f, -1f) -> v = Vector3(1f, -1f, 0f) - Vector3(1f, 0f, -1f) -> v = Vector3(-1f, 1f, 0f) - Vector3(-1f, 0f, 1f) -> v = Vector3(0f, 1f, -1f) - } - return v.cpy() - } - - // Populates an arrayList with all possible moves according to zigzag jump rules - private fun zigzagAlgorithm(position: Vector3, frontier: ArrayList<Vector3>, - moveRange: Int, - jumpRange: Int) { + // Populates a list with all possible basic moves + private fun getBasicMoves(position: Vector3, moveRange: Int, frontier: ArrayList<Vector3>) { - // Repeats algorithm for each direction for (direction: Vector3 in directionalUnitVectors) { - // BASIC MOVE var destination = position.cpy() for (step in 1..moveRange) { @@ -92,40 +77,30 @@ class GameMode(rules:AbstractRules, board:AbstractBoard) { } frontier.add(destination.cpy()) } + } + } - // JUMP MOVE - destination = getPosition(position, direction, jumpRange + 1) + // Populates a list with all possible jumps + private fun getDefaultJumps(position: Vector3, jumpRange: Int, frontier: ArrayList<Vector3>, maxIterations: Int, iterationNumber: Int) { - var secondaryJumpDirection = getSecondaryJumpDirection(direction) - var isPrimaryJumpDirection = true - var jumpable = isPathJumpable(position, direction, destination) + if (iterationNumber < maxIterations) { + for (direction: Vector3 in directionalUnitVectors) { - while (jumpable) { - frontier.add(destination.cpy()) - var newPosition = destination.cpy() - isPrimaryJumpDirection = !isPrimaryJumpDirection - - // Sets direction for next possible move - if (isPrimaryJumpDirection) { - destination = getPosition(newPosition, direction, jumpRange + 1) - jumpable = isPathJumpable(newPosition,direction,destination) - } else { - destination = getPosition(newPosition, secondaryJumpDirection, jumpRange + 1) - jumpable = isPathJumpable(newPosition, secondaryJumpDirection, destination) + var destination = getPosition(position, direction, jumpRange + 1) + + if (isPathJumpable(position, direction, destination)){ + frontier.add(destination.cpy()) + getDefaultJumps(destination, jumpRange, frontier, maxIterations, iterationNumber+1) } } } } + // Choice of gamemode should be implemented here in the future fun getPossibleMoves(position: Vector3): ArrayList<Vector3> { - var possibleMoves: ArrayList<Vector3> = arrayListOf() - zigzagAlgorithm(position, possibleMoves, this.rules.moveRange , this.rules?.jumpRange) + val possibleMoves: ArrayList<Vector3> = arrayListOf() //val????? + getBasicMoves(position, this.rules.moveRange, possibleMoves) + getDefaultJumps(position, this.rules.jumpRange,possibleMoves, this.rules.maxJumps,0) return possibleMoves } } - -// TODO 1. legge inn variabler som standardparametere -// TODO 2. gjøre gamestate og etc private medlemmer -// TODO 3. merge in default-game -// TODO 4. intigerere greier der de skal - diff --git a/CheckersClient/core/src/com/mygdx/game/model/gamemodes/rules/AbstractRules.kt b/CheckersClient/core/src/com/mygdx/game/model/gamemodes/rules/AbstractRules.kt index f04ffa334696e66a59653dd618beabcc631bbfdc..b573330ade056d2c32b9af04d38a2194b03973ec 100644 --- a/CheckersClient/core/src/com/mygdx/game/model/gamemodes/rules/AbstractRules.kt +++ b/CheckersClient/core/src/com/mygdx/game/model/gamemodes/rules/AbstractRules.kt @@ -8,6 +8,7 @@ abstract class AbstractRules { abstract var moveRange: Int // How far a piece can be moved abstract var jumpRange: Int // How many pieces a piece can jump over + abstract var maxJumps: Int // How many jumps can a piece do after each other abstract fun getPlayerStartfields(boardSlot: Int) : List<Vector3> // Returns a list of startfields for a given player diff --git a/CheckersClient/core/src/com/mygdx/game/model/gamemodes/rules/DefaultRules.kt b/CheckersClient/core/src/com/mygdx/game/model/gamemodes/rules/DefaultRules.kt index 14328841473bb5bd348d34af9b1d64f8beafc750..540e77a0595422d34a03125cb53c89de83b36842 100644 --- a/CheckersClient/core/src/com/mygdx/game/model/gamemodes/rules/DefaultRules.kt +++ b/CheckersClient/core/src/com/mygdx/game/model/gamemodes/rules/DefaultRules.kt @@ -9,6 +9,7 @@ class DefaultRules: AbstractRules() { override var startFields = generateStartFields() override var moveRange = 1 override var jumpRange = 1 + override var maxJumps = 6 override fun getPlayerStartfields(boardSlot: Int): List<Vector3> { return startFields[boardSlot]