Skip to content

Commit

Permalink
Merge pull request #25 from AJFaraday/fix_equality_bug
Browse files Browse the repository at this point in the history
Fix equality bug
  • Loading branch information
AJFaraday authored Oct 17, 2019
2 parents 92730d3 + 502cb45 commit 590665b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/classes/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ GridGame.classes.player = function (config) {
var target_is_city = target.city;
var target_already_stepped_to = target.changed_player;
var target_is_rock = target.rock;
var target_is_wall = target.wall; // TODO and wall has health
var target_is_wall = target.wall;
return (
target_present &&
(target_unowned || target_belongs_to_me) &&
Expand Down
12 changes: 7 additions & 5 deletions lib/grid_game.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ var GridGame = {
},

turn_active: false,
callbacks: [],

turn: function () {
$.each(GridGame.apis, function (i, api) {
Expand All @@ -127,25 +128,26 @@ var GridGame = {
GridGame.set_players_dead();

GridGame.board.each_tile(function (tile) {
tile.mark_damage_phase()
tile.mark_damage_phase();
});
GridGame.board.each_tile(function (tile) {
tile.do_damage_phase()
tile.do_damage_phase();
});
GridGame.board.each_tile(function (tile) {
tile.mark_movement_phase()
tile.mark_movement_phase();
});
GridGame.board.each_tile(function (tile) {
tile.do_movement_phase()
tile.do_movement_phase();
});
GridGame.board.draw();

GridGame.check_players_alive();
GridGame.turn_number += 1;
$('span#turn').html(GridGame.turn_number);
if (GridGame.tournament) {
$('span#turn').html(GridGame.turn_number);
GridGame.info.get_all();
}
$.each(GridGame.callbacks, function(i, c) {c()})
},

spawning_turn: function () {
Expand Down
61 changes: 49 additions & 12 deletions lib/turn_phases/mark_movement_phase.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,73 @@
GridGame.turn_phases.mark_movement_phase = function () {
GridGame.turn_phases.mark_movement_phase = function() {

this.mark_movement_phase = function () {
if (this.player && this.value > 0 && !this.city) {
this.mark_movement_phase = function() {
if(this.player && this.value > 0 && !this.city) {
this.move_unit();
} else if (this.player && this.city) {
if (GridGame.spawning_turn()) {
} else if(this.player && this.city) {
if(GridGame.spawning_turn()) {
this.spawn_unit();
}
}
this.mark_player_still_alive();
};

this.move_unit = function () {
this.move_unit = function() {
var move_target = this.move_target();
if (this.player.can_step_onto(move_target)) {
if (this.enemy_walker_at(move_target)) {
this.fight_with(move_target);
} else if (this.player.can_step_onto(move_target)) {
this.value_change -= this.value;
this.player.mark_step_onto(move_target, this.value);
}
};

this.spawn_unit = function () {
this.fight_with = function(target){
if (this.value_cahnge > 0) {
console.log(this.value_change);
}
var target_value = (target.value + target.value_change);
var this_value = (this.value + this.value_change);

var win = (this_value) > target_value;
var draw = this_value == target_value;
var lose = this_value < target_value;
if (win) {
target.value_change -= target_value;
target.value_change += (this_value - target_value);
target.player = this.player;
target.changed_player = true;
} else if (draw) {
this.value_change -= this_value;
target.value_change -= target_value;
} else if (lose) {
target.value_change -= this_value;
this.value_change -= this_value;
}
};

this.enemy_walker_at = function(target) {
return (
target &&
target.player != this.player &&
(target.value > 0 || (target.value + target.value_change) > 0) &&
!target.city
)
};

this.spawn_unit = function() {
var move_target = this.move_target();
if (this.player.can_step_onto(move_target)) {
if (this.enemy_walker_at(move_target)) {
move_target.value_change -= 1;
} else if(this.player.can_step_onto(move_target)) {
this.player.mark_step_onto(move_target, 1);
}
};

this.mark_player_still_alive = function() {
if (this.player && this.value > 0) {
if(this.player && this.value > 0) {
this.player.still_alive = true
}
};

};

38 changes: 26 additions & 12 deletions tournament.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<head>

<script>
(function (i, s, o, g, r, a, m) {
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
Expand Down Expand Up @@ -54,6 +54,7 @@
<script type="text/javascript" src="./lib/api_ui.js"></script>

<link rel="stylesheet" href="./style/grid_game.css"/>
<script src="lib/info.js"></script>
</head>
<body>
<h1>Grid Game</h1>
Expand Down Expand Up @@ -112,36 +113,49 @@ <h1>Grid Game</h1>
<script type="text/javascript">
function set_player_to_gist(colour, gist) {
var api_space;
if (colour == 'green') {
if(colour == 'green') {
api_space = $('div.api_space.api_0');
} else if (colour == 'red') {
} else if(colour == 'red') {
api_space = $('div.api_space.api_1');
}
var select = api_space.find('select');
var options = [];
select.find('option').each(function (i, o) {
select.find('option').each(function(i, o) {
options.push($(o).attr('value'));
});
if (options.includes(gist)) {
if(options.includes(gist)) {
select.val(gist).trigger('change');
} else {
select.val('bot_id').trigger('change');
select.siblings('input').val(gist).trigger('change');
}
}

$(window).ready(function () {
GridGame.init({tournament: true, turn_time: 50});
$(window).ready(function() {
GridGame.init(
{
tournament: true,
turn_time: 50
}
);
GridGame.api_ui.init();
url = new URL(window.location);
red_gist = url.searchParams.get('red');
if (red_gist) {
if(red_gist) {
set_player_to_gist('red', red_gist)
}
green_gist = url.searchParams.get('green');
if (green_gist) {
if(green_gist) {
set_player_to_gist('green', green_gist)
}

GridGame.callbacks.push(
function() {
if ((GridGame.turn_number % 500) == 0) {
GridGame.stop();
}
}
);
});
</script>
</body>
Expand Down

0 comments on commit 590665b

Please sign in to comment.