-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated map and viz, began work on dice mechanic
- Loading branch information
Showing
4 changed files
with
42 additions
and
9 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
.DS_STORE | ||
*.ipynb* | ||
*__pycache__ |
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,17 @@ | ||
import random | ||
import numpy as np | ||
|
||
rng = np.random.default_rng() | ||
sided_die = 6 | ||
attack_max = 3 | ||
defend_max = 2 | ||
attack_until_threshold = 2 | ||
|
||
def single_roll(attack, defend): | ||
attack_roll = np.sort(rng.integers(1,sided_die+1,min(attack_max,attack)))[::-1] | ||
defend_roll = np.sort(rng.integers(1,sided_die+1,min(defend_max,defend)))[::-1] | ||
max_loss = min(len(attack_roll), len(defend_roll)) | ||
attack_wins = np.sum([i>j for i,j in zip(attack_roll,defend_roll)]) | ||
new_attack = attack - max_loss - attack_wins | ||
new_defend = defend - attack_wins | ||
return new_attack, new_defend |
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 |
---|---|---|
@@ -1,24 +1,38 @@ | ||
import random | ||
import json | ||
from pathlib import Path | ||
import networkx as nx | ||
|
||
from maps.debug import debug | ||
|
||
class Map(): | ||
metadata = {} | ||
|
||
def __init__(self): | ||
self.graph = None | ||
pass | ||
def __init__(self, board='us_cont'): | ||
# read in graph | ||
graph_path = Path(__file__).parent / f"assets/{board}_graph.json" | ||
with graph_path.open() as json_file: | ||
graph_data = json.load(json_file) | ||
|
||
def initialize_player_assignment(self): | ||
"""Randomly assigns each player a country until there are none left""" | ||
#Load in map | ||
self.graph = nx.node_link_graph(graph_data) | ||
|
||
# randomize and assign player map | ||
self.graph.nodes = self.initialize_player_assignment() | ||
pass | ||
|
||
|
||
pass | ||
def initialize_player_assignment(self,players=['red','blue']): | ||
"""Randomly assigns each player a country until there are none left""" | ||
graph_nodes = self.graph.nodes | ||
random.shuffle(graph_nodes) | ||
player_list = ['red', 'blue'] | ||
for j,i in enumerate(graph_nodes): | ||
graph_nodes[i]['player'] = player_list[j%len(player_list)] | ||
graph_nodes[i]['units'] = 3 | ||
return graph_nodes | ||
|
||
def change_ownership(self, payload): | ||
"""Change ownership of a country | ||
Params: payload (dict) {node:player} | ||
""" | ||
nx.set_node_attributes(self.graph, payload, "owner") | ||
nx.set_node_attributes(self.graph, payload, "player") | ||
pass |
Empty file.