Skip to content
Snippets Groups Projects
Commit 4855a19e authored by Memo Akten's avatar Memo Akten
Browse files

shoot control

parent 89ed4402
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ public class MemoBattleTest {
SimpleBattle battle = new SimpleBattle();
BattleController player1 = new MemoController1();
BattleController player2 = new WASDController();
BattleController player2 = new MMMCTS();
battle.playGame(player1, player2);
}
......
......@@ -26,7 +26,7 @@ public class MemoController1 implements RenderableBattleController {
public double ATTACK_PROB = 0.1;
public double ATTACK_SHOOT_PROB = 0.3;
public double ATTACK_THRUST_PROB = 0.00;
public double ATTACK_ROT_THRESH = 5 * Math.PI / 180.0;
public double ATTACK_ROT_THRESH = 45 * Math.PI / 180.0;
public double CHASE_SHOOT_PROB = 0.1;
public double CHASE_THRUST_PROB = 0.5;
......@@ -109,8 +109,7 @@ public class MemoController1 implements RenderableBattleController {
// TODO, include velocity vector in target pos
target_pos = new Vector2d(otherShip.s, true);
action.turn = MemoControllerUtils.lookAt(thisShip.s, thisShip.d, otherShip.s, ATTACK_ROT_THRESH);
action.shoot = Math.random() < ATTACK_SHOOT_PROB;
action.shoot = MemoControllerUtils.lookAt(thisShip.s, thisShip.d, otherShip.s, ATTACK_ROT_THRESH, action) && (Math.random() < ATTACK_SHOOT_PROB);
}
if(thisShip.s.dist(otherShip.s) > SHOOT_DIST_THRESH) {
......
......@@ -77,7 +77,7 @@ public class MemoControllerRandom implements BattleController {
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);
MemoControllerUtils.lookAt(thisShip.s, thisShip.d, otherShip.s, ATTACK_ROT_THRESH, action);
} else{
action.thrust = Math.random() < FLEE_THRUST_PROB ? 1 : 0;
action.shoot = Math.random() < FLEE_SHOOT_PROB;
......
......@@ -14,20 +14,19 @@ import asteroids.GameObject;
*/
public class MemoControllerUtils {
// returns turn value (-1, 0, 1)
static double lookAt(Vector2d s, Vector2d d, Vector2d lookat, double rot_threshold) {
// fills in Action with turn, returns whether we or not we've reached target
static boolean lookAt(Vector2d s, Vector2d d, Vector2d lookat, double rot_threshold, Action action) {
Vector2d desired_rot_vec = new Vector2d(lookat, true);
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) < rot_threshold) {
return 0;
} else {
if(current_rot > target_rot) return -1;
else return 1;
}
if(current_rot > target_rot) action.turn = -1;
else action.turn = 1;
return Math.abs(current_rot - target_rot) < rot_threshold;
}
// fills in Action with turn, returns whether we or not we've reached target
......@@ -36,7 +35,7 @@ public class MemoControllerUtils {
if(dist_to_desired_pos < dist_threshold) {
return true;
} else {
action.turn = lookAt(s, d, desired_pos, rot_threshold);
lookAt(s, d, desired_pos, rot_threshold, action);
return false;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment