Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorporate objects defined in yaml configuration into gridworld #248

Merged
merged 38 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5805389
Make object and transition config accessible to client side
jessesnyder Jul 20, 2023
1aacbf7
Remove unsused var
jessesnyder Jul 20, 2023
61936c2
Hard-code a type_id for food, for now
jessesnyder Jul 21, 2023
9beb69d
Replace Food with generic Resource
jessesnyder Jul 21, 2023
e9654de
Add Food to game config
jessesnyder Jul 21, 2023
1757b62
Add some notes
jessesnyder Jul 21, 2023
2eabd8b
incorporate objects defined in yaml configuration into gridworld
cguardia Jul 21, 2023
a2e7e90
Only consume things immediately if they're non-interactive
jessesnyder Jul 21, 2023
6442db1
Merge branch 'issues/233-participants-see-objects' into issues/232-ne…
jessesnyder Jul 21, 2023
d2c809e
Bugfix: attribute name
jessesnyder Jul 21, 2023
61730ae
Add some logging on grid object spawning
jessesnyder Jul 21, 2023
43c5a73
Use YAML config for Food, and remove other objects for now
jessesnyder Jul 21, 2023
130301c
Update attr names in JS to match python
jessesnyder Jul 21, 2023
17b8f4c
Commit compiled JS
jessesnyder Jul 21, 2023
fe9ef39
Use item rather than object or resource
cguardia Jul 22, 2023
4f88723
Commit compiled JS
jessesnyder Jul 24, 2023
ef257ff
tablib is no longer a dependency, so remove related test
jessesnyder Jul 24, 2023
03b09e7
Mechanical changes to get most tests passing again
jessesnyder Jul 24, 2023
02cbb59
Use a shared reference to item_config across Item instances
jessesnyder Jul 24, 2023
6abf932
Move from hard-coding colors to using a "sprite" definition in game_c…
jessesnyder Jul 25, 2023
a2494ee
Add note about possibly avoidable copy of shared values
jessesnyder Jul 25, 2023
4be6708
Port maturation threshold and speed to item config
jessesnyder Jul 26, 2023
4789d8d
Attempt to blindly update grid item deserialization
jessesnyder Jul 26, 2023
44e8614
add black; first black run updates
cguardia Jul 26, 2023
24a775a
add default item config; use item count and calories instead of globa…
cguardia Jul 26, 2023
8ddd3fe
Fix some bugs with replenish_items(), but some still remain
jessesnyder Jul 26, 2023
b44192a
move away form grid based to item based config and evaluation
cguardia Jul 27, 2023
2b86e49
fix merge conflict
cguardia Jul 27, 2023
2d9e251
Update supported python versions
jessesnyder Jul 28, 2023
c768385
Make Item immutable(ish)
jessesnyder Jul 28, 2023
b831c99
Better test isolation
jessesnyder Jul 28, 2023
a2fcae5
Blacken tests
jessesnyder Jul 28, 2023
7b09115
Make instruction test very basic for now
jessesnyder Jul 28, 2023
31e06c6
Greatly reduce mocking and make sure @property patches are removed on…
jessesnyder Jul 28, 2023
e795dc7
Restore docstring
jessesnyder Jul 28, 2023
3d1419b
Restore config.txt, add docstring, remove spurious comment
jessesnyder Jul 31, 2023
395f571
Optimize replenish_items
jessesnyder Jul 31, 2023
2410991
Add player config with distribution config.
alecpm Jul 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dlgr/griduniverse/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ def __init__(self, **kwargs):
def serialize(self):
return {
"id": self.id,
"type_id": 9,
"position": self.position,
"maturity": self.maturity,
"color": self.color or self._maturity_to_rgb(self.maturity),
Expand Down Expand Up @@ -1154,6 +1155,11 @@ def configure(self):
self.transition_config = {
(t['actor_start'], t['target_start']): t for t in self.game_config.get('transitions', ())
}
# This is accessed by the grid.html template to load the configuration on the client side:
self.object_config_json = json.dumps(self.object_config)
self.transition_config_json = json.dumps(
{"{}_{}".format(k[0], k[1]): v for k, v in self.transition_config.items()}
)

@classmethod
def extra_parameters(cls):
Expand Down Expand Up @@ -1239,7 +1245,7 @@ def bonus_reason(self):
)

def dispatch(self, msg):
"""Route to the appropriate method based on message type"""
"""Route incoming messages to the appropriate method based on message type"""
mapping = {
'connect': self.handle_connect,
'disconnect': self.handle_disconnect,
Expand Down
54 changes: 30 additions & 24 deletions dlgr/griduniverse/static/scripts/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ var mouse = position(pixels.canvas);

var isSpectator = false;
var start = performance.now();
var food = [];
var foodConsumed = [];
var resources = [];
var resourcesConsumed = [];
var walls = [];
var wall_map = {};
var row, column, rand;
Expand Down Expand Up @@ -151,15 +151,23 @@ var color2name = function (color) {
return settings.player_color_names[idx];
};

var Food = function (settings) {
if (!(this instanceof Food)) {
return new Food();
}
this.id = settings.id;
this.position = settings.position;
this.color = settings.color;
return this;
};
/**
* Representation of a game resource, which for the moment is limited to a
* simple Food type.
*
* @param {*} data Information passed from the server, including the type ID
* @returns Object with merged server state + object definition values
*/
function Resource(data) {
cguardia marked this conversation as resolved.
Show resolved Hide resolved
obj = {
type_id: data.type_id,
id: data.id,
position: data.position,
color: data.color,
};

return Object.assign(obj, settings.object_config[obj.type_id]);
}

var Wall = function (settings) {
if (!(this instanceof Wall)) {
Expand Down Expand Up @@ -561,7 +569,6 @@ pixels.frame(function() {
// Update the background.
var ego = players.ego(),
w = getWindowPosition(),
limitVisibility,
dimness,
rescaling,
i, j, x, y;
Expand All @@ -575,15 +582,13 @@ pixels.frame(function() {
return newColor;
});

for (i = 0; i < food.length; i++) {
// Players digest the food.
var cur_food = food[i];
if (players.isPlayerAt(cur_food.position)) {
foodConsumed.push(food.splice(i, 1));
for (i = 0; i < resources.length; i++) {
// Players digests the resource if possible.
var currentResource = resources[i];
if (players.isPlayerAt(currentResource.position)) {
resourcesConsumed.push(resources.splice(i, 1)); // XXX this does nothing, AFAICT (Jesse)
} else {
if (settings.food_visible) {
section.plot(cur_food.position[1], cur_food.position[0], cur_food.color);
}
section.plot(currentResource.position[1], currentResource.position[0], currentResource.color);
}
}

Expand Down Expand Up @@ -952,13 +957,14 @@ function onGameStateChange(msg) {

updateDonationStatus(state.donation_active);

// Update food.
// Update resources
if (state.food !== undefined && state.food !== null) {
food = [];
resources = [];
for (j = 0; j < state.food.length; j++) {
food.push(
new Food({
resources.push(
Resource({
id: state.food[j].id,
type_id: state.food[j].type_id,
position: state.food[j].position,
color: state.food[j].color
})
Expand Down
Loading