Commit 25f4b9d5 authored by Anders H. Rebner's avatar Anders H. Rebner
Browse files

Merge branch 'default-game' of...

Merge branch 'default-game' of https://gitlab.stud.idi.ntnu.no/tdt4240-progark/tdt4240-progark-project into default-game
parents b1113fbe 25eba0ec
......@@ -23,8 +23,9 @@ public class NetworkController {
this.client = new Client();
client.start();
try {
String IP4_LAN_ADDRESS = "192.168.0.136";
String IP4_LAN_ADDRESS = "192.168.0.109";
client.connect(10000, IP4_LAN_ADDRESS, 54555);
} catch (IOException e) {
e.printStackTrace();
}
......
......@@ -46,7 +46,9 @@ class GameMode(rules:AbstractRules, board:AbstractBoard) {
}
private fun isPathJumpable(position: Vector3, direction: Vector3, destination: Vector3): Boolean {
val v = position.cpy().add(direction)
while (v != destination) {
if (isFieldClear(v) || !this.board.fieldExists(v)) {
return false
......@@ -59,28 +61,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) {
......@@ -91,40 +76,31 @@ 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) {
val 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())
val 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> {
val possibleMoves: ArrayList<Vector3> = arrayListOf()
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
}
}
// 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
abstract fun getPlayerTargetFields(boardSlot: Int) : List<Vector3> // Returns a list of targetfields 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]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment