Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asteroids
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hexboard-games
asteroids
Commits
800233ab
Commit
800233ab
authored
9 years ago
by
Piers Williams
Browse files
Options
Downloads
Patches
Plain Diff
Started work on neurons
parent
e6827789
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/battle/controllers/PiersController.java
+64
-0
64 additions, 0 deletions
src/battle/controllers/PiersController.java
with
64 additions
and
0 deletions
src/battle/controllers/PiersController.java
+
64
−
0
View file @
800233ab
...
...
@@ -2,15 +2,79 @@ package battle.controllers;
import
asteroids.Action
;
import
battle.BattleController
;
import
battle.NeuroShip
;
import
battle.SimpleBattle
;
import
java.util.Random
;
/**
* Created by pwillic on 11/06/2015.
*
* Features to use for avoidance
*
* 1. Distance to enemy - 0 very close, 1 very far
* 2. Enemy in FL - 0 no, 1 yes
* 3. Enemy in FR
* 4. Enemy in BL
* 5. Enemy in BR
*
* Features to use for shooting
* 1. Distance to enemy
* 2. Deviance from dead straight Left - 0.5 no deviance, 0 full left, 1 full right
* 3. Missiles Remaining
*
* Features to use for aligning
* 1. Distance to enemy
* 2. Deviance from enemy
* 3.
*/
public
class
PiersController
implements
BattleController
{
Neuron
tinyBrain
;
public
PiersController
()
{
tinyBrain
=
new
Neuron
(
10
);
}
@Override
public
Action
getAction
(
SimpleBattle
gameStateCopy
,
int
playerId
)
{
double
[]
avoidanceTable
=
new
double
[
5
];
double
[]
shootingTable
=
new
double
[
3
];
return
null
;
}
}
class
Neuron
{
private
static
Random
random
=
new
Random
();
int
numberOfInputs
;
double
[]
neuronWeights
;
// Random neuron
public
Neuron
(
int
numberOfInputs
)
{
this
.
numberOfInputs
=
numberOfInputs
;
this
.
neuronWeights
=
new
double
[
numberOfInputs
];
for
(
int
i
=
0
;
i
<
neuronWeights
.
length
;
i
++)
{
neuronWeights
[
i
]
=
random
.
nextDouble
();
}
}
// clone a neuron / make one
public
Neuron
(
double
[]
neuronWeights
)
{
this
.
numberOfInputs
=
neuronWeights
.
length
;
this
.
neuronWeights
=
neuronWeights
;
}
public
double
think
(
double
[]
inputs
)
{
if
(
inputs
.
length
!=
numberOfInputs
)
throw
new
IllegalArgumentException
(
"Wrong number of inputs"
+
inputs
.
length
+
" - should be: "
+
numberOfInputs
);
double
totalSum
=
0
;
for
(
int
index
=
0
;
index
<
numberOfInputs
;
index
++)
{
totalSum
+=
(
inputs
[
index
]
*
neuronWeights
[
index
]);
}
return
totalSum
;
}
}
\ No newline at end of file
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