Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SpaceCheckers
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TDT4240-group23
SpaceCheckers
Commits
462becd2
Commit
462becd2
authored
4 years ago
by
morkolai
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Completed first version of possible moves algorithm
parent
b7d24ba3
Branches
Branches containing commit
No related tags found
1 merge request
!14
WIP: Default game
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
CheckersClient/core/src/com/mygdx/game/model/GameMode.kt
+33
-6
33 additions, 6 deletions
CheckersClient/core/src/com/mygdx/game/model/GameMode.kt
with
33 additions
and
6 deletions
CheckersClient/core/src/com/mygdx/game/model/GameMode.kt
+
33
−
6
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
}
fun
algorithm
(
pos
:
Vector3
,
frontier
:
ArrayList
<
Vector3
>,
iterationNumber
:
Int
=
0
)
{
if
(
this
.
board
?.
fields
?.
get
(
position
)
?.
hasPiece
()
==
true
)
{
val
iterationCount
:
Int
=
1
// algoritme
for
(
dir
:
Vector3
in
directionalUnitVectors
)
{
return
frontier
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
)
}
}
}
var
possibleMoves
:
ArrayList
<
Vector3
>
=
arrayListOf
()
algorithm
(
position
,
possibleMoves
)
return
possibleMoves
return
frontier
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment