Skip to content
Snippets Groups Projects
Commit 26344985 authored by morkolai's avatar morkolai
Browse files

Original moves are now working

parent afe399b7
Branches
No related tags found
1 merge request!14WIP: Default game
...@@ -23,8 +23,10 @@ public class NetworkController { ...@@ -23,8 +23,10 @@ public class NetworkController {
this.client = new Client(); this.client = new Client();
client.start(); client.start();
try { 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) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -47,7 +47,9 @@ class GameMode(rules:AbstractRules, board:AbstractBoard) { ...@@ -47,7 +47,9 @@ class GameMode(rules:AbstractRules, board:AbstractBoard) {
} }
private fun isPathJumpable(position: Vector3, direction: Vector3, destination: Vector3): Boolean { 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) { while (v != destination) {
if (isFieldClear(v) || this.board?.fieldExists(v) == false) { if (isFieldClear(v) || this.board?.fieldExists(v) == false) {
return false return false
...@@ -60,28 +62,11 @@ class GameMode(rules:AbstractRules, board:AbstractBoard) { ...@@ -60,28 +62,11 @@ class GameMode(rules:AbstractRules, board:AbstractBoard) {
return false return false
} }
private fun getSecondaryJumpDirection(direction: Vector3): Vector3 { // Populates a list with all possible basic moves
var v = Vector3(0f,0f,0f) private fun getBasicMoves(position: Vector3, moveRange: Int, frontier: ArrayList<Vector3>) {
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) {
// Repeats algorithm for each direction
for (direction: Vector3 in directionalUnitVectors) { for (direction: Vector3 in directionalUnitVectors) {
// BASIC MOVE
var destination = position.cpy() var destination = position.cpy()
for (step in 1..moveRange) { for (step in 1..moveRange) {
...@@ -92,40 +77,30 @@ class GameMode(rules:AbstractRules, board:AbstractBoard) { ...@@ -92,40 +77,30 @@ class GameMode(rules:AbstractRules, board:AbstractBoard) {
} }
frontier.add(destination.cpy()) frontier.add(destination.cpy())
} }
}
}
// JUMP MOVE // Populates a list with all possible jumps
destination = getPosition(position, direction, jumpRange + 1) private fun getDefaultJumps(position: Vector3, jumpRange: Int, frontier: ArrayList<Vector3>, maxIterations: Int, iterationNumber: Int) {
var secondaryJumpDirection = getSecondaryJumpDirection(direction) if (iterationNumber < maxIterations) {
var isPrimaryJumpDirection = true for (direction: Vector3 in directionalUnitVectors) {
var jumpable = isPathJumpable(position, direction, destination)
while (jumpable) { var destination = getPosition(position, direction, jumpRange + 1)
frontier.add(destination.cpy())
var newPosition = destination.cpy()
isPrimaryJumpDirection = !isPrimaryJumpDirection
// Sets direction for next possible move if (isPathJumpable(position, direction, destination)){
if (isPrimaryJumpDirection) { frontier.add(destination.cpy())
destination = getPosition(newPosition, direction, jumpRange + 1) getDefaultJumps(destination, jumpRange, frontier, maxIterations, iterationNumber+1)
jumpable = isPathJumpable(newPosition,direction,destination)
} else {
destination = getPosition(newPosition, secondaryJumpDirection, jumpRange + 1)
jumpable = isPathJumpable(newPosition, secondaryJumpDirection, destination)
} }
} }
} }
} }
// Choice of gamemode should be implemented here in the future
fun getPossibleMoves(position: Vector3): ArrayList<Vector3> { fun getPossibleMoves(position: Vector3): ArrayList<Vector3> {
var possibleMoves: ArrayList<Vector3> = arrayListOf() val possibleMoves: ArrayList<Vector3> = arrayListOf() //val?????
zigzagAlgorithm(position, possibleMoves, this.rules.moveRange , this.rules?.jumpRange) getBasicMoves(position, this.rules.moveRange, possibleMoves)
getDefaultJumps(position, this.rules.jumpRange,possibleMoves, this.rules.maxJumps,0)
return possibleMoves 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
...@@ -8,6 +8,7 @@ abstract class AbstractRules { ...@@ -8,6 +8,7 @@ abstract class AbstractRules {
abstract var moveRange: Int // How far a piece can be moved 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 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 abstract fun getPlayerStartfields(boardSlot: Int) : List<Vector3> // Returns a list of startfields for a given player
......
...@@ -9,6 +9,7 @@ class DefaultRules: AbstractRules() { ...@@ -9,6 +9,7 @@ class DefaultRules: AbstractRules() {
override var startFields = generateStartFields() override var startFields = generateStartFields()
override var moveRange = 1 override var moveRange = 1
override var jumpRange = 1 override var jumpRange = 1
override var maxJumps = 6
override fun getPlayerStartfields(boardSlot: Int): List<Vector3> { override fun getPlayerStartfields(boardSlot: Int): List<Vector3> {
return startFields[boardSlot] return startFields[boardSlot]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment