Skip to content

Commit

Permalink
Merge branch 'thenamangoyal:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasbai98 authored Oct 9, 2021
2 parents 1df93fd + 42224c4 commit 071d799
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 89 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<http://www.cs.columbia.edu/~kar/4444f21/node19.html>

[Documentation](https://docs.google.com/document/d/1wCQZNEupmkwjPrOVFU3S3sMxz16ph3gBDZg0aunx46Q/edit?usp=sharing)

## Installation

Requires **python3.6**
Expand Down
17 changes: 13 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import json
import logging
import argparse
from random_player import Player as Random_Player
from players.random_player import Player as Random_Player
from players.g1_player import Player as G1_Player
from players.g2_player import Player as G2_Player
from players.g3_player import Player as G3_Player
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self, args):
self.served_this_turn = None

if self.use_gui:
start(IceCreamApp, address=args.address, port=args.port, start_browser=not(args.no_browser), userdata=(self, None))
start(IceCreamApp, address=args.address, port=args.port, start_browser=not(args.no_browser), update_interval=0.5, userdata=(self, None))
else:
self.logger.debug("No GUI flag specified")
self.play_all()
Expand Down Expand Up @@ -282,11 +282,15 @@ def main(self, *userdata):
mainContainer.style['justify-content'] = 'center'
mainContainer.style['align-items'] = 'center'

bt_hbox = gui.HBox(width="30%", style={'text-align': 'center', 'margin': 'auto'})
bt_hbox = gui.HBox(width="40%", style={'text-align': 'center', 'margin': 'auto'})
play_step_bt = gui.Button("Play Step")
play_turn_bt = gui.Button("Play Turn")
play_all_bt = gui.Button("Play All")
bt_hbox.append([play_step_bt, play_turn_bt, play_all_bt])

self.automatic_play = gui.CheckBoxLabel("Play Automatically")
self.automatic_play.attributes["class"] = "checkbox"

bt_hbox.append([play_step_bt, play_turn_bt, play_all_bt, self.automatic_play])

play_step_bt.onclick.do(self.play_step_bt_press)
play_turn_bt.onclick.do(self.play_turn_bt_press)
Expand Down Expand Up @@ -325,6 +329,11 @@ def main(self, *userdata):

return mainContainer

def idle(self):
if self.automatic_play.get_value():
self.ice_cream_game.play(run_stepwise=True)


def update_score_table(self):
for player_idx, score in enumerate(self.ice_cream_game.player_scores):
self.score_table.item_at(0, player_idx).set_text("{}".format(self.ice_cream_game.player_names[player_idx]))
Expand Down
14 changes: 7 additions & 7 deletions players/g10_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, flavor_preference: List[int], rng: np.random.Generator, logge
"""Initialise the player with given preference.
Args:
flavor_preference (List[int]): flavor preference, least flavored flavor is first element in the list and most flavored is most preferred
flavor_preference (List[int]): flavor preference, most flavored flavor is first element in the list and last element is least preferred flavor
rng (np.random.Generator): numpy random number generator, use this for same player behvior across run
logger (logging.Logger): logger use this like logger.info("message")
"""
Expand All @@ -20,19 +20,19 @@ def __init__(self, flavor_preference: List[int], rng: np.random.Generator, logge
self.state = None

def serve(self, top_layer: np.ndarray, curr_level: np.ndarray, player_idx: int, get_flavors: Callable[[], List[int]], get_player_count: Callable[[], int], get_served: Callable[[], List[Dict[int, int]]], get_turns_received: Callable[[], List[int]]) -> Dict[str, Union[Tuple[int], int]]:
"""Request what to scoop or whom to pass in the given step of the turn. In each turn the simulator calls this serve function mulitple times for each step for a single player, until the player has scooped 24 units of ice-cream or asked to pass to next player or made an invalid request. If you have scooped 24 units of ice-cream in a turn then you get one last step in that turn where you can specify to pass to a player.
"""Request what to scoop or whom to pass in the given step of the turn. In each turn the simulator calls this serve function multiple times for each step for a single player, until the player has scooped 24 units of ice-cream or asked to pass to next player or made an invalid request. If you have scooped 24 units of ice-cream in a turn then you get one last step in that turn where you can specify to pass to a player.
Args:
top_layer (np.ndarray): Numpy 2d array of size (24, 15) containing flavor at each cell location
curr_level (np.ndarray): Numpy 2d array of size (24, 15) containing current level at each cell location from 8 to 0, where 8 is highest level at start and 0 means no icecream left at this level
player_idx (int): index of your player, 0-indexed
get_flavors (Callable[[], List[int]]): list of all possible flavors
get_player_count (Callable[[], int]): number of total players
get_served (Callable[[], List[Dict[int, int]]]): returns a list of dictionaries corresponding to each player, each dictionary at index i tells how units of a flavor are present in the bowl of the player with index i. E.g. lets say the fourth element is {1: 0, 2: 8...} means the corresponding player with index 4 has 0 units of flavor 1 and 8 units of flavor
get_turns_received (Callable[[], List[int]]): returns a list of integers corresponding to each player, each element at index i tells how many turns a player with index i has played so far.
get_flavors (Callable[[], List[int]]): method which returns a list of all possible flavors
get_player_count (Callable[[], int]): method which returns number of total players
get_served (Callable[[], List[Dict[int, int]]]): method which returns a list of dictionaries corresponding to each player, each dictionary at index i tells how units of a flavor are present in the bowl of the player with index i. E.g. lets say the fourth element is {1: 0, 2: 8...} means the corresponding player with index 4 has 0 units of flavor 1 and 8 units of flavor
get_turns_received (Callable[[], List[int]]): method which returns a list of integers corresponding to each player, each element at index i tells how many turns a player with index i has played so far.
Returns:
Dict[str, Union[Tuple[int],int]]: Return a dictionary of action to take in next step.
Dict[str, Union[Tuple[int],int]]: Return a dictionary specifying what action to take in the next step.
2 possible return values
{"action": "scoop", "values" : (i,j)} stating to scoop the 4 cells with index (i,j), (i+1,j), (i,j+1), (i+1,j+1)
{"action": "pass", "values" : i} pass to next player with index i
Expand Down
14 changes: 7 additions & 7 deletions players/g1_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, flavor_preference: List[int], rng: np.random.Generator, logge
"""Initialise the player with given preference.
Args:
flavor_preference (List[int]): flavor preference, least flavored flavor is first element in the list and most flavored is most preferred
flavor_preference (List[int]): flavor preference, most flavored flavor is first element in the list and last element is least preferred flavor
rng (np.random.Generator): numpy random number generator, use this for same player behvior across run
logger (logging.Logger): logger use this like logger.info("message")
"""
Expand All @@ -20,19 +20,19 @@ def __init__(self, flavor_preference: List[int], rng: np.random.Generator, logge
self.state = None

def serve(self, top_layer: np.ndarray, curr_level: np.ndarray, player_idx: int, get_flavors: Callable[[], List[int]], get_player_count: Callable[[], int], get_served: Callable[[], List[Dict[int, int]]], get_turns_received: Callable[[], List[int]]) -> Dict[str, Union[Tuple[int], int]]:
"""Request what to scoop or whom to pass in the given step of the turn. In each turn the simulator calls this serve function mulitple times for each step for a single player, until the player has scooped 24 units of ice-cream or asked to pass to next player or made an invalid request. If you have scooped 24 units of ice-cream in a turn then you get one last step in that turn where you can specify to pass to a player.
"""Request what to scoop or whom to pass in the given step of the turn. In each turn the simulator calls this serve function multiple times for each step for a single player, until the player has scooped 24 units of ice-cream or asked to pass to next player or made an invalid request. If you have scooped 24 units of ice-cream in a turn then you get one last step in that turn where you can specify to pass to a player.
Args:
top_layer (np.ndarray): Numpy 2d array of size (24, 15) containing flavor at each cell location
curr_level (np.ndarray): Numpy 2d array of size (24, 15) containing current level at each cell location from 8 to 0, where 8 is highest level at start and 0 means no icecream left at this level
player_idx (int): index of your player, 0-indexed
get_flavors (Callable[[], List[int]]): list of all possible flavors
get_player_count (Callable[[], int]): number of total players
get_served (Callable[[], List[Dict[int, int]]]): returns a list of dictionaries corresponding to each player, each dictionary at index i tells how units of a flavor are present in the bowl of the player with index i. E.g. lets say the fourth element is {1: 0, 2: 8...} means the corresponding player with index 4 has 0 units of flavor 1 and 8 units of flavor
get_turns_received (Callable[[], List[int]]): returns a list of integers corresponding to each player, each element at index i tells how many turns a player with index i has played so far.
get_flavors (Callable[[], List[int]]): method which returns a list of all possible flavors
get_player_count (Callable[[], int]): method which returns number of total players
get_served (Callable[[], List[Dict[int, int]]]): method which returns a list of dictionaries corresponding to each player, each dictionary at index i tells how units of a flavor are present in the bowl of the player with index i. E.g. lets say the fourth element is {1: 0, 2: 8...} means the corresponding player with index 4 has 0 units of flavor 1 and 8 units of flavor
get_turns_received (Callable[[], List[int]]): method which returns a list of integers corresponding to each player, each element at index i tells how many turns a player with index i has played so far.
Returns:
Dict[str, Union[Tuple[int],int]]: Return a dictionary of action to take in next step.
Dict[str, Union[Tuple[int],int]]: Return a dictionary specifying what action to take in the next step.
2 possible return values
{"action": "scoop", "values" : (i,j)} stating to scoop the 4 cells with index (i,j), (i+1,j), (i,j+1), (i+1,j+1)
{"action": "pass", "values" : i} pass to next player with index i
Expand Down
14 changes: 7 additions & 7 deletions players/g2_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, flavor_preference: List[int], rng: np.random.Generator, logge
"""Initialise the player with given preference.
Args:
flavor_preference (List[int]): flavor preference, least flavored flavor is first element in the list and most flavored is most preferred
flavor_preference (List[int]): flavor preference, most flavored flavor is first element in the list and last element is least preferred flavor
rng (np.random.Generator): numpy random number generator, use this for same player behvior across run
logger (logging.Logger): logger use this like logger.info("message")
"""
Expand All @@ -20,19 +20,19 @@ def __init__(self, flavor_preference: List[int], rng: np.random.Generator, logge
self.state = None

def serve(self, top_layer: np.ndarray, curr_level: np.ndarray, player_idx: int, get_flavors: Callable[[], List[int]], get_player_count: Callable[[], int], get_served: Callable[[], List[Dict[int, int]]], get_turns_received: Callable[[], List[int]]) -> Dict[str, Union[Tuple[int], int]]:
"""Request what to scoop or whom to pass in the given step of the turn. In each turn the simulator calls this serve function mulitple times for each step for a single player, until the player has scooped 24 units of ice-cream or asked to pass to next player or made an invalid request. If you have scooped 24 units of ice-cream in a turn then you get one last step in that turn where you can specify to pass to a player.
"""Request what to scoop or whom to pass in the given step of the turn. In each turn the simulator calls this serve function multiple times for each step for a single player, until the player has scooped 24 units of ice-cream or asked to pass to next player or made an invalid request. If you have scooped 24 units of ice-cream in a turn then you get one last step in that turn where you can specify to pass to a player.
Args:
top_layer (np.ndarray): Numpy 2d array of size (24, 15) containing flavor at each cell location
curr_level (np.ndarray): Numpy 2d array of size (24, 15) containing current level at each cell location from 8 to 0, where 8 is highest level at start and 0 means no icecream left at this level
player_idx (int): index of your player, 0-indexed
get_flavors (Callable[[], List[int]]): list of all possible flavors
get_player_count (Callable[[], int]): number of total players
get_served (Callable[[], List[Dict[int, int]]]): returns a list of dictionaries corresponding to each player, each dictionary at index i tells how units of a flavor are present in the bowl of the player with index i. E.g. lets say the fourth element is {1: 0, 2: 8...} means the corresponding player with index 4 has 0 units of flavor 1 and 8 units of flavor
get_turns_received (Callable[[], List[int]]): returns a list of integers corresponding to each player, each element at index i tells how many turns a player with index i has played so far.
get_flavors (Callable[[], List[int]]): method which returns a list of all possible flavors
get_player_count (Callable[[], int]): method which returns number of total players
get_served (Callable[[], List[Dict[int, int]]]): method which returns a list of dictionaries corresponding to each player, each dictionary at index i tells how units of a flavor are present in the bowl of the player with index i. E.g. lets say the fourth element is {1: 0, 2: 8...} means the corresponding player with index 4 has 0 units of flavor 1 and 8 units of flavor
get_turns_received (Callable[[], List[int]]): method which returns a list of integers corresponding to each player, each element at index i tells how many turns a player with index i has played so far.
Returns:
Dict[str, Union[Tuple[int],int]]: Return a dictionary of action to take in next step.
Dict[str, Union[Tuple[int],int]]: Return a dictionary specifying what action to take in the next step.
2 possible return values
{"action": "scoop", "values" : (i,j)} stating to scoop the 4 cells with index (i,j), (i+1,j), (i,j+1), (i+1,j+1)
{"action": "pass", "values" : i} pass to next player with index i
Expand Down
14 changes: 7 additions & 7 deletions players/g3_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, flavor_preference: List[int], rng: np.random.Generator, logge
"""Initialise the player with given preference.
Args:
flavor_preference (List[int]): flavor preference, least flavored flavor is first element in the list and most flavored is most preferred
flavor_preference (List[int]): flavor preference, most flavored flavor is first element in the list and last element is least preferred flavor
rng (np.random.Generator): numpy random number generator, use this for same player behvior across run
logger (logging.Logger): logger use this like logger.info("message")
"""
Expand All @@ -20,19 +20,19 @@ def __init__(self, flavor_preference: List[int], rng: np.random.Generator, logge
self.state = None

def serve(self, top_layer: np.ndarray, curr_level: np.ndarray, player_idx: int, get_flavors: Callable[[], List[int]], get_player_count: Callable[[], int], get_served: Callable[[], List[Dict[int, int]]], get_turns_received: Callable[[], List[int]]) -> Dict[str, Union[Tuple[int], int]]:
"""Request what to scoop or whom to pass in the given step of the turn. In each turn the simulator calls this serve function mulitple times for each step for a single player, until the player has scooped 24 units of ice-cream or asked to pass to next player or made an invalid request. If you have scooped 24 units of ice-cream in a turn then you get one last step in that turn where you can specify to pass to a player.
"""Request what to scoop or whom to pass in the given step of the turn. In each turn the simulator calls this serve function multiple times for each step for a single player, until the player has scooped 24 units of ice-cream or asked to pass to next player or made an invalid request. If you have scooped 24 units of ice-cream in a turn then you get one last step in that turn where you can specify to pass to a player.
Args:
top_layer (np.ndarray): Numpy 2d array of size (24, 15) containing flavor at each cell location
curr_level (np.ndarray): Numpy 2d array of size (24, 15) containing current level at each cell location from 8 to 0, where 8 is highest level at start and 0 means no icecream left at this level
player_idx (int): index of your player, 0-indexed
get_flavors (Callable[[], List[int]]): list of all possible flavors
get_player_count (Callable[[], int]): number of total players
get_served (Callable[[], List[Dict[int, int]]]): returns a list of dictionaries corresponding to each player, each dictionary at index i tells how units of a flavor are present in the bowl of the player with index i. E.g. lets say the fourth element is {1: 0, 2: 8...} means the corresponding player with index 4 has 0 units of flavor 1 and 8 units of flavor
get_turns_received (Callable[[], List[int]]): returns a list of integers corresponding to each player, each element at index i tells how many turns a player with index i has played so far.
get_flavors (Callable[[], List[int]]): method which returns a list of all possible flavors
get_player_count (Callable[[], int]): method which returns number of total players
get_served (Callable[[], List[Dict[int, int]]]): method which returns a list of dictionaries corresponding to each player, each dictionary at index i tells how units of a flavor are present in the bowl of the player with index i. E.g. lets say the fourth element is {1: 0, 2: 8...} means the corresponding player with index 4 has 0 units of flavor 1 and 8 units of flavor
get_turns_received (Callable[[], List[int]]): method which returns a list of integers corresponding to each player, each element at index i tells how many turns a player with index i has played so far.
Returns:
Dict[str, Union[Tuple[int],int]]: Return a dictionary of action to take in next step.
Dict[str, Union[Tuple[int],int]]: Return a dictionary specifying what action to take in the next step.
2 possible return values
{"action": "scoop", "values" : (i,j)} stating to scoop the 4 cells with index (i,j), (i+1,j), (i,j+1), (i+1,j+1)
{"action": "pass", "values" : i} pass to next player with index i
Expand Down
Loading

0 comments on commit 071d799

Please sign in to comment.