Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hexagon
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CE810
hexagon
Commits
81508a87
Commit
81508a87
authored
May 15, 2018
by
Joseph Walton-Rivers
🐈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add hexagon code to git
parents
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
1505 additions
and
0 deletions
+1505
-0
.gitignore
.gitignore
+3
-0
pom.xml
pom.xml
+29
-0
CloneOrder.java
src/main/java/com/fossgalaxy/games/hexagon/CloneOrder.java
+29
-0
CloneTo.java
src/main/java/com/fossgalaxy/games/hexagon/CloneTo.java
+66
-0
HexOrder.java
src/main/java/com/fossgalaxy/games/hexagon/HexOrder.java
+90
-0
HexagonEditor.java
...main/java/com/fossgalaxy/games/hexagon/HexagonEditor.java
+15
-0
Hexagons.java
src/main/java/com/fossgalaxy/games/hexagon/Hexagons.java
+15
-0
JumpOrder.java
src/main/java/com/fossgalaxy/games/hexagon/JumpOrder.java
+33
-0
JumpTo.java
src/main/java/com/fossgalaxy/games/hexagon/JumpTo.java
+67
-0
MostPieces.java
src/main/java/com/fossgalaxy/games/hexagon/MostPieces.java
+94
-0
Hexagon-ai.json
src/main/resources/Hexagon-ai.json
+4
-0
Hexagon-board.json
src/main/resources/Hexagon-board.json
+362
-0
Hexagon-eval.json
src/main/resources/Hexagon-eval.json
+4
-0
Hexagon-resources.json
src/main/resources/Hexagon-resources.json
+13
-0
Hexagon-rules.json
src/main/resources/Hexagon-rules.json
+4
-0
Hexagon-stuck.json
src/main/resources/Hexagon-stuck.json
+626
-0
Hexagon-terrain.json
src/main/resources/Hexagon-terrain.json
+5
-0
Hexagon-types.json
src/main/resources/Hexagon-types.json
+31
-0
Hexagon.json
src/main/resources/Hexagon.json
+15
-0
gold.png
src/main/resources/img/gold.png
+0
-0
white.png
src/main/resources/img/terrain/white.png
+0
-0
a.png
src/main/resources/img/units/a.png
+0
-0
g.png
src/main/resources/img/units/g.png
+0
-0
puffin.png
src/main/resources/img/units/puffin.png
+0
-0
suborbitalpigeon.png
src/main/resources/img/units/suborbitalpigeon.png
+0
-0
webpigeon_head.png
src/main/resources/img/units/webpigeon_head.png
+0
-0
No files found.
.gitignore
0 → 100644
View file @
81508a87
target/
.idea/
*.iml
pom.xml
0 → 100644
View file @
81508a87
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.fossgalaxy.games.hexagon
</groupId>
<artifactId>
hexagon
</artifactId>
<version>
0.1-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<name>
Hexagon
</name>
<parent>
<groupId>
com.fossgalaxy.common
</groupId>
<artifactId>
parent-pom
</artifactId>
<version>
0.4
</version>
</parent>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
com.fossgalaxy.games.tbs
</groupId>
<artifactId>
basic-tbs
</artifactId>
<version>
0.1-SNAPSHOT
</version>
</dependency>
</dependencies>
</project>
src/main/java/com/fossgalaxy/games/hexagon/CloneOrder.java
0 → 100644
View file @
81508a87
package
com
.
fossgalaxy
.
games
.
hexagon
;
import
com.fossgalaxy.games.tbs.GameState
;
import
com.fossgalaxy.games.tbs.entity.Entity
;
import
com.fossgalaxy.games.tbs.parameters.ResourceType
;
import
org.codetome.hexameter.core.api.CubeCoordinate
;
public
class
CloneOrder
extends
HexOrder
{
public
CloneOrder
(
CubeCoordinate
newPos
,
ResourceType
lockResouce
)
{
super
(
newPos
,
lockResouce
);
}
@Override
public
void
doOrder
(
Entity
entity
,
GameState
gameState
)
{
if
(!
isLegal
(
entity
,
gameState
,
1
)
||
!
useMoveLock
(
entity
.
getOwner
(),
gameState
,
lockResouce
))
{
return
;
}
// update the position
Entity
child
=
new
Entity
(
entity
.
getType
(),
newPos
,
entity
.
getOwner
());
gameState
.
addEntity
(
child
);
// update my peoples
updateAfterMove
(
gameState
,
child
);
}
}
src/main/java/com/fossgalaxy/games/hexagon/CloneTo.java
0 → 100644
View file @
81508a87
package
com
.
fossgalaxy
.
games
.
hexagon
;
import
com.fossgalaxy.games.tbs.GameState
;
import
com.fossgalaxy.games.tbs.actions.AbstractAction
;
import
com.fossgalaxy.games.tbs.entity.Entity
;
import
com.fossgalaxy.games.tbs.order.Order
;
import
com.fossgalaxy.games.tbs.parameters.ResourceType
;
import
com.fossgalaxy.games.tbs.parameters.TerrainType
;
import
com.fossgalaxy.object.annotations.ObjectDef
;
import
org.codetome.hexameter.core.api.CubeCoordinate
;
import
java.awt.*
;
public
class
CloneTo
extends
AbstractAction
{
private
static
final
Color
CLONE_HINT
=
new
Color
(
173
,
255
,
47
,
100
);
private
ResourceType
lock
;
@ObjectDef
(
"Clone"
)
public
CloneTo
(
ResourceType
lock
){
this
.
lock
=
lock
;
}
@Override
public
boolean
isPossible
(
Entity
entity
,
GameState
s
,
CubeCoordinate
co
)
{
//cannot move into occupied space
Entity
entityAtPos
=
s
.
getEntityAt
(
co
);
if
(
entityAtPos
!=
null
)
{
return
false
;
}
//cannot jump at any range other than 2
int
range
=
s
.
getDistance
(
entity
.
getPos
(),
co
);
if
(
range
!=
1
)
{
return
false
;
}
//check the entity is allowed to move to the space
TerrainType
type
=
s
.
getTerrainAt
(
co
);
if
(
type
==
null
||
!
type
.
isPassible
(
entity
)){
return
false
;
}
return
HexOrder
.
hasMoveAvailable
(
entity
.
getOwner
(),
s
,
lock
);
}
@Override
public
Order
generateOrder
(
CubeCoordinate
cubeCoordinate
,
GameState
gameState
)
{
return
new
CloneOrder
(
cubeCoordinate
,
lock
);
}
@Override
public
Color
getHintColour
()
{
return
CLONE_HINT
;
}
@Override
public
Color
getBorderColour
()
{
return
Color
.
GREEN
;
}
@Override
public
String
toString
()
{
return
"clone"
;
}
}
src/main/java/com/fossgalaxy/games/hexagon/HexOrder.java
0 → 100644
View file @
81508a87
package
com
.
fossgalaxy
.
games
.
hexagon
;
import
com.fossgalaxy.games.tbs.GameState
;
import
com.fossgalaxy.games.tbs.entity.Entity
;
import
com.fossgalaxy.games.tbs.entity.HexagonTile
;
import
com.fossgalaxy.games.tbs.order.Order
;
import
com.fossgalaxy.games.tbs.parameters.ResourceType
;
import
org.codetome.hexameter.core.api.CubeCoordinate
;
import
org.codetome.hexameter.core.api.Hexagon
;
import
java.util.Collection
;
public
class
HexOrder
implements
Order
{
protected
final
CubeCoordinate
newPos
;
protected
final
ResourceType
lockResouce
;
public
HexOrder
(
CubeCoordinate
newPos
,
ResourceType
lockResouce
)
{
this
.
newPos
=
newPos
;
this
.
lockResouce
=
lockResouce
;
}
public
boolean
isLegal
(
Entity
entity
,
GameState
gameState
,
int
distance
){
//can't jump where someone is
Entity
currEntity
=
gameState
.
getEntityAt
(
newPos
);
if
(
currEntity
!=
null
)
{
return
false
;
}
//can only jump distance
if
(
gameState
.
getDistance
(
entity
.
getPos
(),
newPos
)
!=
distance
)
{
return
false
;
}
//can only perform legal moves
if
(!
gameState
.
getTerrainAt
(
newPos
).
isPassible
(
entity
))
{
return
false
;
}
return
true
;
}
public
static
boolean
hasMoveAvailable
(
int
playerID
,
GameState
gameState
,
ResourceType
lockResouce
)
{
int
currTurn
=
gameState
.
getResource
(
playerID
,
lockResouce
);
return
currTurn
<=
gameState
.
getTime
();
}
public
static
boolean
useMoveLock
(
int
playerID
,
GameState
gameState
,
ResourceType
lockResouce
)
{
if
(!
hasMoveAvailable
(
playerID
,
gameState
,
lockResouce
))
{
return
false
;
}
//execute lock
gameState
.
setResource
(
playerID
,
lockResouce
,
gameState
.
getTime
()
+
1
);
return
true
;
}
public
void
updateAfterMove
(
GameState
state
,
Entity
entity
)
{
Collection
<
Hexagon
<
HexagonTile
>>
neighbors
=
state
.
getNeighbors
(
entity
.
getPos
());
for
(
Hexagon
<
HexagonTile
>
neighbor
:
neighbors
)
{
Entity
nEntity
=
state
.
getEntityAt
(
neighbor
.
getCubeCoordinate
());
if
(
nEntity
!=
null
&&
nEntity
.
getOwner
()
!=
entity
.
getOwner
())
{
// changing owner doens't work right - need to delete and re-add
state
.
removeEntity
(
nEntity
);
nEntity
.
setType
(
entity
.
getType
());
nEntity
.
setOwner
(
entity
.
getOwner
());
state
.
addEntity
(
nEntity
);
//warning, if it's legal to issue moves to this unit you'll get disqualified!
}
}
}
@Override
public
void
doOrder
(
Entity
entity
,
GameState
gameState
)
{
if
(!
isLegal
(
entity
,
gameState
,
2
)
||
!
useMoveLock
(
entity
.
getOwner
(),
gameState
,
lockResouce
))
{
return
;
}
// update the position
entity
.
setPos
(
newPos
);
// update my peoples
updateAfterMove
(
gameState
,
entity
);
}
}
src/main/java/com/fossgalaxy/games/hexagon/HexagonEditor.java
0 → 100644
View file @
81508a87
package
com
.
fossgalaxy
.
games
.
hexagon
;
import
com.fossgalaxy.games.tbs.editor.Editor
;
import
com.fossgalaxy.games.tbs.io.SettingsIO
;
import
com.fossgalaxy.games.tbs.io.map2.MapDef
;
import
com.fossgalaxy.games.tbs.parameters.GameSettings
;
public
class
HexagonEditor
{
public
static
void
main
(
String
[]
args
)
{
SettingsIO
io
=
SettingsIO
.
buildWithExtras
(
"com.fossgalaxy.games.hexagon"
);
Editor
.
run
(
io
,
"Hexagon.json"
,
"Hexagon-map.json"
);
}
}
\ No newline at end of file
src/main/java/com/fossgalaxy/games/hexagon/Hexagons.java
0 → 100644
View file @
81508a87
package
com
.
fossgalaxy
.
games
.
hexagon
;
import
com.fossgalaxy.games.tbs.App
;
import
com.fossgalaxy.games.tbs.io.SettingsIO
;
import
com.fossgalaxy.games.tbs.io.map2.MapDef
;
import
com.fossgalaxy.games.tbs.parameters.GameSettings
;
public
class
Hexagons
{
public
static
void
main
(
String
[]
args
)
{
SettingsIO
io
=
SettingsIO
.
buildWithExtras
(
"com.fossgalaxy.games.hexagon"
);
App
.
run
(
io
,
"Hexagon.json"
,
"Hexagon-stuck.json"
,
"Player"
,
"Player"
);
}
}
\ No newline at end of file
src/main/java/com/fossgalaxy/games/hexagon/JumpOrder.java
0 → 100644
View file @
81508a87
package
com
.
fossgalaxy
.
games
.
hexagon
;
import
com.fossgalaxy.games.tbs.GameState
;
import
com.fossgalaxy.games.tbs.entity.Entity
;
import
com.fossgalaxy.games.tbs.entity.HexagonTile
;
import
com.fossgalaxy.games.tbs.order.Order
;
import
com.fossgalaxy.games.tbs.parameters.ResourceType
;
import
org.codetome.hexameter.core.api.CubeCoordinate
;
import
org.codetome.hexameter.core.api.Hexagon
;
import
java.util.Collection
;
public
class
JumpOrder
extends
HexOrder
{
public
JumpOrder
(
CubeCoordinate
newPos
,
ResourceType
lockResouce
)
{
super
(
newPos
,
lockResouce
);
}
@Override
public
void
doOrder
(
Entity
entity
,
GameState
gameState
)
{
if
(!
isLegal
(
entity
,
gameState
,
2
)
||
!
useMoveLock
(
entity
.
getOwner
(),
gameState
,
lockResouce
))
{
return
;
}
// update the position
entity
.
setPos
(
newPos
);
// update my peoples
updateAfterMove
(
gameState
,
entity
);
}
}
src/main/java/com/fossgalaxy/games/hexagon/JumpTo.java
0 → 100644
View file @
81508a87
package
com
.
fossgalaxy
.
games
.
hexagon
;
import
com.fossgalaxy.games.tbs.GameState
;
import
com.fossgalaxy.games.tbs.actions.AbstractAction
;
import
com.fossgalaxy.games.tbs.entity.Entity
;
import
com.fossgalaxy.games.tbs.order.Order
;
import
com.fossgalaxy.games.tbs.parameters.ResourceType
;
import
com.fossgalaxy.games.tbs.parameters.TerrainType
;
import
com.fossgalaxy.object.annotations.ObjectDef
;
import
org.codetome.hexameter.core.api.CubeCoordinate
;
import
java.awt.*
;
public
class
JumpTo
extends
AbstractAction
{
private
static
final
Color
JUMP_HINT
=
new
Color
(
255
,
255
,
224
,
200
);
private
ResourceType
lock
;
@ObjectDef
(
"Jump"
)
public
JumpTo
(
ResourceType
lock
){
this
.
lock
=
lock
;
}
@Override
public
boolean
isPossible
(
Entity
entity
,
GameState
s
,
CubeCoordinate
co
)
{
//cannot move into occupied space
Entity
entityAtPos
=
s
.
getEntityAt
(
co
);
if
(
entityAtPos
!=
null
)
{
return
false
;
}
//cannot jump at any range other than 2
int
range
=
s
.
getDistance
(
entity
.
getPos
(),
co
);
if
(
range
!=
2
)
{
return
false
;
}
// check we're allowed to move there
TerrainType
type
=
s
.
getTerrainAt
(
co
);
if
(
type
==
null
||
!
type
.
isPassible
(
entity
)){
return
false
;
}
return
HexOrder
.
hasMoveAvailable
(
entity
.
getOwner
(),
s
,
lock
);
}
@Override
public
Order
generateOrder
(
CubeCoordinate
cubeCoordinate
,
GameState
gameState
)
{
return
new
JumpOrder
(
cubeCoordinate
,
lock
);
}
@Override
public
Color
getHintColour
()
{
return
JUMP_HINT
;
}
@Override
public
Color
getBorderColour
()
{
return
Color
.
YELLOW
;
}
@Override
public
String
toString
(){
return
"jump"
;
}
}
src/main/java/com/fossgalaxy/games/hexagon/MostPieces.java
0 → 100644
View file @
81508a87
package
com
.
fossgalaxy
.
games
.
hexagon
;
import
com.fossgalaxy.games.tbs.GameState
;
import
com.fossgalaxy.games.tbs.entity.Entity
;
import
com.fossgalaxy.games.tbs.entity.HexagonTile
;
import
com.fossgalaxy.games.tbs.parameters.ResourceType
;
import
com.fossgalaxy.games.tbs.rules.Rule
;
import
com.fossgalaxy.games.tbs.ui.GameAction
;
import
com.fossgalaxy.object.annotations.ObjectDef
;
import
com.fossgalaxy.object.annotations.ObjectDefStatic
;
import
org.codetome.hexameter.core.api.Hexagon
;
import
java.util.Collection
;
import
java.util.List
;
public
class
MostPieces
implements
Rule
{
private
final
int
numHexs
;
private
final
String
lock
;
@ObjectDef
(
"MostPiecesLock"
)
public
MostPieces
(
int
numHexes
,
String
lock
){
this
.
numHexs
=
numHexes
;
this
.
lock
=
lock
;
}
@ObjectDefStatic
(
"MostPieces"
)
public
static
MostPieces
MostPieces
(
int
numHexes
){
return
new
MostPieces
(
numHexes
,
null
);
}
public
Integer
getWinner
(
GameState
state
)
{
int
numEntities
=
state
.
getEntities
().
size
();
if
(
numEntities
==
numHexs
)
{
return
countWinner
(
state
);
}
for
(
int
playerID
=
0
;
playerID
<
state
.
getNumberOfPlayers
();
playerID
++)
{
if
(
lock
!=
null
&&
!
HexOrder
.
hasMoveAvailable
(
playerID
,
state
,
state
.
getSettings
().
getResourceType
(
lock
)
))
{
continue
;
}
if
(
isStuck
(
playerID
,
state
))
{
return
countWinner
(
state
);
}
}
return
Rule
.
NO_WINNER
;
}
protected
boolean
isStuck
(
int
playerID
,
GameState
state
){
Collection
<
Entity
>
currEntities
=
state
.
getOwnedEntities
(
playerID
);
for
(
Entity
curr
:
currEntities
)
{
List
<
GameAction
>
actionList
=
curr
.
getType
().
getAvailableActions
();
for
(
GameAction
action
:
actionList
)
{
//this agent can't do anything - don't do the expensive check.
if
(!
action
.
isPossible
(
curr
,
state
))
{
continue
;
}
int
range
=
action
.
getRange
(
curr
);
Collection
<
Hexagon
<
HexagonTile
>>
tilesInRange
=
state
.
getRange
(
curr
.
getPos
(),
range
);
boolean
actionPossible
=
tilesInRange
.
stream
().
anyMatch
(
h
->
action
.
isPossible
(
curr
,
state
,
h
.
getCubeCoordinate
()));
if
(
actionPossible
)
{
return
false
;
}
}
}
return
true
;
}
protected
Integer
countWinner
(
GameState
state
){
int
largestArmy
=
0
;
Integer
winningPlayer
=
Rule
.
NO_WINNER
;
for
(
int
playerID
=
0
;
playerID
<
state
.
getNumberOfPlayers
();
playerID
++)
{
int
nPieces
=
state
.
getOwnedEntities
(
playerID
).
size
();
if
(
nPieces
>
largestArmy
)
{
largestArmy
=
nPieces
;
winningPlayer
=
playerID
;
}
}
return
winningPlayer
;
}
}
src/main/resources/Hexagon-ai.json
0 → 100644
View file @
81508a87
{
"random"
:
"RandomController"
,
"noop"
:
"NoOpController"
}
src/main/resources/Hexagon-board.json
0 → 100644
View file @
81508a87
{
"width"
:
11
,
"height"
:
11
,
"players"
:
2
,
"hexSize"
:
60
,
"resources"
:
[],
"entities"
:
[
{
"type"
:
"gems"
,
"location"
:
{
"x"
:
-1
,
"z"
:
5
},
"owner"
:
0
,
"properties"
:
{
"health"
:
1
}
},
{
"type"
:
"gems"
,
"location"
:
{
"x"
:
3
,
"z"
:
9
},
"owner"
:
0
,
"properties"
:
{
"health"
:
1
}
},
{
"type"
:
"gems"
,
"location"
:
{
"x"
:
7
,
"z"
:
1
},
"owner"
:
0
,
"properties"
:
{
"health"
:
1
}
},
{
"type"
:
"pearls"
,
"location"
:
{
"x"
:
3
,
"z"
:
1
},
"owner"
:
1
,
"properties"
:
{
"health"
:
1
}
},
{
"type"
:
"pearls"
,
"location"
:
{
"x"
:
7
,
"z"
:
5
},
"owner"
:
1
,
"properties"
:
{
"health"
:
1
}
},
{
"type"
:
"pearls"
,
"location"
:
{
"x"
:
-1
,
"z"
:
9
},
"owner"
:
1
,
"properties"
:
{
"health"
:
1
}
}
],
"terrain"
:
{
"board-edge"
:
[
{
"x"
:
3
,
"z"
:
0
},
{
"x"
:
4
,
"z"
:
0
},
{
"x"
:
5
,
"z"
:
0
},
{
"x"
:
6
,
"z"
:
0
},
{
"x"
:
7
,
"z"
:
0
},
{
"x"
:
2
,
"z"
:
1
},
{
"x"
:
1
,
"z"
:
2
},
{
"x"
:
0
,
"z"
:
3
},
{
"x"
:
-1
,
"z"
:
4
},
{
"x"
:
4
,
"z"
:
4
},
{
"x"
:
2
,
"z"
:
5
},
{
"x"
:
3
,
"z"
:
6
}
],
"board"
:
[
{
"x"
:
3
,
"z"
:
1
},
{
"x"
:
4
,
"z"
:
1
},
{
"x"
:
5
,
"z"
:
1
},
{
"x"
:
6
,
"z"
:
1
},
{
"x"
:
7
,
"z"
:
1
},
{
"x"
:
2
,
"z"
:
2
},
{
"x"
:
3
,
"z"
:
2
},
{
"x"
:
4
,
"z"
:
2
},
{
"x"
:
5
,
"z"
:
2
},
{
"x"
:
6
,
"z"
:
2
},
{
"x"
:
7
,
"z"
:
2
},
{
"x"
:
1
,
"z"
:
3
},
{
"x"
:
2
,
"z"
:
3
},
{
"x"
:
3
,
"z"
:
3
},
{
"x"
:
4
,
"z"
:
3
},
{
"x"
:
5
,
"z"
:
3
},
{
"x"
:
6
,
"z"
:
3
},
{
"x"
:
7
,
"z"
:
3
},
{
"x"
:
0
,
"z"
:
4
},
{
"x"
:
1
,
"z"
:
4
},
{
"x"
:
2
,
"z"
:
4
},
{
"x"
:
3
,
"z"
:
4
},
{
"x"
:
5
,
"z"
:
4
},
{
"x"
:
6
,
"z"
:
4
},
{
"x"
:
7
,
"z"
:
4
},
{
"x"
:
-1
,
"z"
:
5
},
{
"x"
:
0
,
"z"
:
5
},
{
"x"
:
1
,
"z"
:
5
},
{
"x"
:
3
,
"z"
:
5
},
{
"x"
:
4
,
"z"
:
5
},
{