-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'experiment_bots' into gh-pages
- Loading branch information
Showing
19 changed files
with
457 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
GridGame.data.bots = { | ||
'All Towards': '808c86eb544d9efaf94a30efc91bdfaf', | ||
'Code on Page': 'code', | ||
'Faraday Cage': 'd9eb9a70ad0dc0fb1885be0fce032adc', | ||
'Gist Id': 'bot_id', | ||
'Long Random': 'b9a0fe99060d9be1fc617bb7262f57be', | ||
'Manual': 'manual', | ||
'Rotate': '6634a7f381bb679ee7c2d90d93588d66', | ||
'Short Random': 'b16df33acb0f0c7830d2ca2d656f80be' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
GridGame.data.players = [ | ||
{ | ||
name: 'green', | ||
start: GridGame.positions.north_west_corner(2), | ||
direction: 'east', | ||
playable: true, | ||
towardsX: 'east', | ||
towardsY: 'south', | ||
awayX: 'west', | ||
awayY: 'north' | ||
}, | ||
{ | ||
name: 'red', | ||
start: GridGame.positions.south_east_corner(2), | ||
direction: 'west', | ||
playable: true, | ||
towardsX: 'west', | ||
towardsY: 'north', | ||
awayX: 'east', | ||
awayY: 'south' | ||
} | ||
// Only 2 for API-driven game | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
GridGame.api_ui = { | ||
init: function() { | ||
$.each( | ||
GridGame.apis, | ||
function(i, api) { | ||
var space = $('<div>') | ||
.addClass('api_space') | ||
.addClass('api_' + i); | ||
api.sel = $('<select>').data('api-index', i).data('api', api); | ||
api.sel.on('change', function() {GridGame.api_ui.set_source(api)}); | ||
$.each( | ||
GridGame.data.bots, | ||
function(name, gist) { | ||
api.sel.append( | ||
$('<option>') | ||
.attr('value', gist) | ||
.html(name) | ||
); | ||
} | ||
); | ||
space.append(api.sel); | ||
api.id_field = $('<input>').css('display', 'none'); | ||
space.append(api.id_field); | ||
api.id_field.on('change', function() {GridGame.api_ui.set_source(api)}); | ||
|
||
api.code_field = $('<textarea>').css('display', 'none').addClass('code_field'); | ||
api.code_field.attr('rows', 20); | ||
space.append(api.code_field); | ||
api.code_field.on('change', function() {GridGame.api_ui.set_source(api)}); | ||
$('#forms').append(space); | ||
GridGame.api_ui.set_source(api); | ||
} | ||
); | ||
|
||
this.init_button_actions(); | ||
}, | ||
|
||
set_source: function(api) { | ||
switch(api.sel.val()) { | ||
case 'code': | ||
api.code_field.show(); | ||
api.id_field.hide(); | ||
api.func = function() {eval(api.code_field.val())}; | ||
api.player.playable = false; | ||
break; | ||
case 'bot_id': | ||
api.id_field.show(); | ||
api.get_gist(api.id_field.val()); | ||
api.player.playable = false; | ||
break; | ||
case 'manual': | ||
api.func = function() {}; | ||
api.player.playable = true; | ||
break; | ||
default: | ||
api.get_gist(api.sel.val()); | ||
api.id_field.hide(); | ||
api.code_field.hide(); | ||
api.player.playable = false; | ||
} | ||
}, | ||
|
||
init_button_actions: function() { | ||
$('.button[data-action="start"]').on('click', function() {GridGame.start()}); | ||
$('.button[data-action="stop"]').on('click', function() {GridGame.stop()}); | ||
$('.button[data-action="reset"]').on('click', function() {GridGame.reset()}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
GridGame.apis = []; | ||
GridGame.classes.api = function(player, config) { | ||
GridGame.apis.push(this); | ||
this.player = player; | ||
|
||
this.get_named_bot = function(name) { | ||
var bot = GridGame.data.bots[name]; | ||
if (bot === undefined) { | ||
console.log("No known bot named " + name); | ||
} else { | ||
this.get_gist(bot); | ||
} | ||
}; | ||
|
||
|
||
this.func = function() {}; | ||
|
||
this.get_gist = function(id) { | ||
var api = this; | ||
$.get( | ||
'https://api.github.com/gists/'+id, | ||
function(response) { | ||
var code = response.files['bot.js'].content; | ||
console.log(code); | ||
api.func = function() {eval(code)}; | ||
} | ||
) | ||
}; | ||
|
||
this.towardsX = function() { | ||
this.player.change_direction(config.towardsX); | ||
}; | ||
|
||
this.towardsY = function() { | ||
this.player.change_direction(config.towardsY); | ||
}; | ||
|
||
this.awayX = function() { | ||
this.player.change_direction(config.awayX); | ||
}; | ||
|
||
this.awayY = function() { | ||
this.player.change_direction(config.awayY); | ||
}; | ||
|
||
this.random_direction = function() { | ||
this.player.go_random_direction(); | ||
} | ||
|
||
this.turn = function() { | ||
return GridGame.turn_number; | ||
}; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.