Skip to content

Commit

Permalink
Adjusted the unit tests. All 38 succeed.
Browse files Browse the repository at this point in the history
Adjusted the game_init to work according to the input pattern.
Adjusted the shot ammo decrease in action_shoot.
Renamed the test input file.
  • Loading branch information
Marcelo Politzer Couto committed May 6, 2012
1 parent 87b994c commit 5f6cd18
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions bind.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ static foreign_t consult_position(term_t X, term_t Y)
if (!PL_is_variable(X) || !PL_is_variable(Y)) if (!PL_is_variable(X) || !PL_is_variable(Y))
return FALSE; return FALSE;


if (!PL_unify_integer(X, player.x)) return FALSE; if (!PL_unify_integer(X, player.x + 1)) return FALSE;
if (!PL_unify_integer(Y, player.y)) return FALSE; if (!PL_unify_integer(Y, player.y + 1)) return FALSE;
return TRUE; return TRUE;
} }


Expand All @@ -196,8 +196,8 @@ static foreign_t consult_direction(term_t Dir)


static foreign_t consult_goal(term_t X, term_t Y) static foreign_t consult_goal(term_t X, term_t Y)
{ {
if (!PL_unify_integer(X, GI.goal_x)) return FALSE; if (!PL_unify_integer(X, GI.goal_x + 1)) return FALSE;
if (!PL_unify_integer(Y, GI.goal_y)) return FALSE; if (!PL_unify_integer(Y, GI.goal_y + 1)) return FALSE;
return TRUE; return TRUE;
} }


Expand Down Expand Up @@ -277,6 +277,7 @@ static foreign_t action_shoot(void)


if(player.ammo == 0) if(player.ammo == 0)
return FALSE; return FALSE;
player.ammo--;


game_update_points(ACTION_SHOOT); game_update_points(ACTION_SHOOT);
while(game_check_border(x, y)) while(game_check_border(x, y))
Expand Down
8 changes: 4 additions & 4 deletions game.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ void game_update_points(int action)


void game_init(void) void game_init(void)
{ {
GI.goal_x = 18; GI.goal_x = 17;
GI.goal_y = 17; GI.goal_y = 16;
player.x = 3; player.x = 2;
player.y = 3; player.y = 2;
player.ammo = 30; player.ammo = 30;
player.antidotes = 1; player.antidotes = 1;
player.direction = DIR_E; player.direction = DIR_E;
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions teste.pl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
test(sense_zombies_3) :- sense_zombies(N), assertion(N==3). test(sense_zombies_3) :- sense_zombies(N), assertion(N==3).
test(sense_station_0,fail) :- sense_station. test(sense_station_0,fail) :- sense_station.
test(sense_hospital_1) :- sense_hospital. test(sense_hospital_1) :- sense_hospital.
test(sense_antidote_0) :- sense_antidote(N), assertion(N==0). test(sense_antidote_0,fail) :- sense_antidote(N), assertion(N==0).
test(sense_ammo_0) :- sense_ammo(N), assertion(N==0). test(sense_ammo_0,fail) :- sense_ammo(N), assertion(N==0).
test(sense_hit_0,fail) :- sense_hit. test(sense_hit_0,fail) :- sense_hit.


test(action_turn_north) :- action_turn_right, action_turn_right, action_turn_right. test(action_turn_north) :- action_turn_right, action_turn_right, action_turn_right.
Expand All @@ -22,7 +22,7 @@
test(sense_zombies_2) :- sense_zombies(N), assertion(N==2). test(sense_zombies_2) :- sense_zombies(N), assertion(N==2).
test(action_move_forward) :- action_move_forward. test(action_move_forward) :- action_move_forward.
test(consult_bites_2) :- consult_bites(N), assertion(N==2). test(consult_bites_2) :- consult_bites(N), assertion(N==2).
test(consult_ammo_29) :- consult_ammo(N), asssertion(N==29). test(consult_ammo_29) :- consult_ammo(N), assertion(N==29).
test(action_use_antidote) :- action_use_antidote. test(action_use_antidote) :- action_use_antidote.
test(consult_antidotes_0) :- consult_antidotes(N), assertion(N==0). test(consult_antidotes_0) :- consult_antidotes(N), assertion(N==0).
test(consult_bites_0) :- consult_bites(N), assertion(N==0). test(consult_bites_0) :- consult_bites(N), assertion(N==0).
Expand All @@ -42,7 +42,7 @@
test(action_grab) :- action_grab. test(action_grab) :- action_grab.
test(consult_ammo_31) :- consult_ammo(N), assertion(N==31). test(consult_ammo_31) :- consult_ammo(N), assertion(N==31).


test(action_shoot) :- action_shoot. test(action_shoot,fail) :- action_shoot.
test(sense_hit_0,fail) :- sense_hit. test(sense_hit_0,fail) :- sense_hit.


:- end_tests(test). :- end_tests(test).

0 comments on commit 5f6cd18

Please sign in to comment.