Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
TDT4240-group23
SpaceCheckers
Commits
462becd2
Commit
462becd2
authored
Apr 11, 2021
by
morkolai
Browse files
WIP: Completed first version of possible moves algorithm
parent
b7d24ba3
Changes
1
Hide whitespace changes
Inline
Side-by-side
CheckersClient/core/src/com/mygdx/game/model/GameMode.kt
View file @
462becd2
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
p
ossibleMoves
(
position
:
Vector3
):
ArrayList
<
Vector3
>
{
fun
getP
ossibleMoves
(
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
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment