Commit 462becd2 authored by morkolai's avatar morkolai
Browse files

WIP: Completed first version of possible moves algorithm

parent b7d24ba3
package com.mygdx.game.model
import com.badlogic.gdx.math.Vector3
import com.sun.org.apache.xpath.internal.operations.Bool
import java.lang.Exception
import java.lang.NullPointerException
//Holds a ruleset and a board
......@@ -30,18 +33,42 @@ class GameMode(rules:AbstractRules? = null, board:AbstractBoard? = null) {
return this.rules
}
fun possibleMoves(position: Vector3): ArrayList<Vector3> {
fun getPossibleMoves(position: Vector3): ArrayList<Vector3> {
var frontier: ArrayList<Vector3> = arrayListOf()
fun isInBoard(pos: Vector3): Boolean {
var inBoard: Boolean
try {
inBoard = this.board!!.fieldExists(pos)
} catch (e: NullPointerException) {
inBoard = false
}
return inBoard
}
fun hasPiece(pos: Vector3): Boolean {
return (this.board?.fields?.get(pos)?.hasPiece()) ?: false
}
if (this.board?.fields?.get(position)?.hasPiece() == true) {
fun algorithm(pos: Vector3, frontier: ArrayList<Vector3>, iterationNumber: Int = 0) {
// algoritme
val iterationCount: Int = 1
return frontier
for (dir:Vector3 in directionalUnitVectors) {
var newPos:Vector3 = pos.add(dir)
if (isInBoard(newPos) && hasPiece(newPos) && iterationNumber < iterationCount) {
algorithm(newPos,frontier, iterationNumber+1)
} else if (isInBoard(newPos) && !hasPiece(newPos)) {
frontier.add(newPos)
}
}
}
return frontier
var possibleMoves: ArrayList<Vector3> = arrayListOf()
algorithm(position, possibleMoves)
return possibleMoves
}
}
......
Supports Markdown
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