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
3e3333e0
Commit
3e3333e0
authored
9 years ago
by
Memo Akten
Browse files
Options
Downloads
Patches
Plain Diff
MemoControllerUtils.thrustTo
parent
007f57b5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/battle/controllers/Memo/MemoControllerRandom.java
+3
-1
3 additions, 1 deletion
src/battle/controllers/Memo/MemoControllerRandom.java
src/battle/controllers/Memo/MemoControllerUtils.java
+15
-2
15 additions, 2 deletions
src/battle/controllers/Memo/MemoControllerUtils.java
with
18 additions
and
3 deletions
src/battle/controllers/Memo/MemoControllerRandom.java
+
3
−
1
View file @
3e3333e0
...
...
@@ -17,7 +17,7 @@ public class MemoControllerRandom implements BattleController {
public
double
ATTACK_PROB
=
0.1
;
public
double
ATTACK_SHOOT_PROB
=
1
;
public
double
ATTACK_THRUST_PROB
=
0.01
;
public
double
ATTACK_ROT_THRESH
=
0.1
;
public
double
ATTACK_ROT_THRESH
=
0.
0
1
;
public
double
FLEE_ROT_CHANGE_PROB
=
0.3
;
public
double
FLEE_SHOOT_PROB
=
0.1
;
public
double
FLEE_THRUST_PROB
=
0.8
;
...
...
@@ -38,6 +38,8 @@ public class MemoControllerRandom implements BattleController {
if
(
Math
.
random
()
<
ATTACK_PROB
)
{
action
.
thrust
=
Math
.
random
()
<
ATTACK_THRUST_PROB
?
1
:
0
;
action
.
shoot
=
Math
.
random
()
<
ATTACK_SHOOT_PROB
;
// TODO, include velocity vector in target pos
action
.
turn
=
MemoControllerUtils
.
lookAt
(
thisShip
.
s
,
thisShip
.
d
,
otherShip
.
s
,
ATTACK_ROT_THRESH
);
}
else
{
action
.
thrust
=
Math
.
random
()
<
FLEE_THRUST_PROB
?
1
:
0
;
...
...
This diff is collapsed.
Click to expand it.
src/battle/controllers/Memo/MemoControllerUtils.java
+
15
−
2
View file @
3e3333e0
package
battle.controllers.Memo
;
import
math.Vector2d
;
import
asteroids.Action
;
/**
* Created by Memo Akten on 11/06/2015.
*/
public
class
MemoControllerUtils
{
static
double
lookAt
(
Vector2d
s
,
Vector2d
d
,
Vector2d
lookat
,
double
threshold
)
{
// returns turn value (-1, 0, 1)
static
double
lookAt
(
Vector2d
s
,
Vector2d
d
,
Vector2d
lookat
,
double
rot_threshold
)
{
Vector2d
desired_rot_vec
=
lookat
.
copy
();
desired_rot_vec
.
add
(
s
,
-
1
);
double
current_rot
=
Math
.
atan2
(
d
.
y
,
d
.
x
);
double
target_rot
=
Math
.
atan2
(
desired_rot_vec
.
y
,
desired_rot_vec
.
x
);
if
(
Math
.
abs
(
current_rot
-
target_rot
)
<
threshold
)
{
if
(
Math
.
abs
(
current_rot
-
target_rot
)
<
rot_
threshold
)
{
return
0
;
}
else
{
if
(
current_rot
>
target_rot
)
return
-
1
;
...
...
@@ -21,5 +23,16 @@ public class MemoControllerUtils {
}
}
// fills in Action with turn and thrust
static
double
thrustTo
(
Vector2d
s
,
Vector2d
d
,
Vector2d
desired_pos
,
double
dist_threshold
,
double
rot_threshold
,
Action
action
)
{
double
dist_to_desired_pos
=
s
.
dist
(
desired_pos
);
if
(
dist_to_desired_pos
<
dist_threshold
)
{
action
.
thrust
=
0
;
}
else
{
action
.
thrust
=
1
;
action
.
turn
=
lookAt
(
s
,
d
,
desired_pos
,
rot_threshold
);
}
return
action
.
thrust
;
}
}
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