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

Original moves are now working

parent afe399b7
No related branches found
No related tags found
1 merge request!14WIP: Default game
......@@ -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();
}
......
......@@ -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
......@@ -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
......
......@@ -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]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment