song_match

song_match.config

song_match.config.ROOT_DIR = '/home/docs/checkouts/readthedocs.org/user_builds/cozmo-song-match/checkouts/latest/song_match'

Root directory of the package to help load .wav files.

song_match.config.init_mixer() → None[source]

Initializes pygame’s mixer module by calling init().

See https://www.pygame.org/docs/ref/mixer.html#pygame.mixer.init.

IMPORTANT: Must be called before constructing any Note objects.

Returns:None

song_match.cube_mat

class song_match.cube_mat.CubeMat[source]

Bases: object

Class to convert cube IDs to mat positions and vise versa.

Each cube has an ID of 1, 2, or 3 associated with it.

Consider the following cubes with IDs from left to right:

 _______      _______     _______
|       |    |       |   |       |
|   2   |    |   1   |   |   3   |
|_______|    |_______|   |_______|

The mat position of each cube from the player’s perspective is as follows:

 _______      _______     _______
|       |    |       |   |       |
|   1   |    |   2   |   |   3   |
|_______|    |_______|   |_______|

Where the the left-most position is assigned 1, middle position 2, and right-most position 3.

This class is responsible for converting from one to the other.

In this example, the conversion from cube id to mat position is:

  • 2 -> 1
  • 1 -> 2
  • 3 -> 3
classmethod cube_id_to_position(cube_id: int) → int[source]

Maps the cube_id to a mat position.

Parameters:cube_idcube_id
Returns:The ordered cube ID.
classmethod get_light_cubes(song_robot) → List[cozmo.objects.LightCube][source]

Convenience method to get a list of light cubes.

Note:
This is duplicated in song_match.cube.util due to import issues.
Parameters:song_robotSongRobot
Returns:A list of three LightCube instances.
classmethod get_positions() → List[int][source]

Get a list of mat positions ordered by cube ID.

Returns:A list of mat positions ordered by cube ID.
classmethod order_cubes_by_position(song_robot) → None[source]

Assign each cube ID to a mat position.

Parameters:song_robotSongRobot
Returns:None
classmethod position_to_cube_id(cube_id: int) → int[source]

Maps a mat position to a cube_id.

Parameters:cube_id – The ordered cube ID.
Returns:cube_id

song_match.game_constants

song_match.game_constants.MAX_STRIKES = 3

The maximum number of notes a player can get wrong

song_match.game_constants.STARTING_POSITION = 3

The number of notes you start with in the sequence

song_match.game_constants.TIME_IN_BETWEEN_PLAYERS_AND_COZMO = 1

Time in seconds to wait in between the players and Cozmo

song_match.option_prompter

class song_match.option_prompter.OptionPrompter(song_robot: song_match.song_robot.SongRobot)[source]

Bases: object

A class to help the user select an option from three different choices.

get_option(prompt: str, options: List[str]) → int[source]

Prompts the user to select from three different options by tapping a cube.

  1. Cozmo will prompt the user with prompt.
  2. Cozmo will point to each cube saying the corresponding option.
  3. The light chaser effect will start signaling the game is awaiting user input.
  4. Upon successful tap collect-point.wav is played and the cube flashes green.
Parameters:
  • prompt – The prompt for Cozmo to say.
  • options – A list of options associated with each cube.
Returns:

cube_id of the tapped cube.

song_match.player

class song_match.player.Player(player_id: int)[source]

Bases: object

Represents a human player.

did_win

Property for accessing whether the player won the game.

Returns:Whether the player won the game.

song_match.song_match

Module containing SongMatch.

class song_match.song_match.SongMatch(song: song_match.song.song.Song = None, num_players: int = None)[source]

Bases: object

Main game class.

play(robot: cozmo.robot.Robot) → None[source]

Play the Song Match game.

Pass this function into cozmo.run_program().

Parameters:robot (Robot) – Cozmo Robot instance.
Returns:None

song_match.song_robot

Module containing SongRobot.

class song_match.song_robot.SongRobot(robot: cozmo.robot.Robot, song: song_match.song.song.Song)[source]

Bases: object

Wrapper class for Cozmo Robot instance.

did_win

Property for accessing whether Cozmo won the game.

Returns:Whether Cozmo won the game.
play_anim(animation_name: str, **kwargs) → cozmo.anim.Animation[source]

Wrapper method for play_anim().

Parameters:
  • animation_name – The name of the animation.
  • kwargs – See play_anim().
Returns:

Animation

play_anim_trigger(animation_trigger, **kwargs) → cozmo.anim.AnimationTrigger[source]

Wrapper method for play_anim_trigger().

Parameters:
Returns:

AnimationTrigger

play_note(note: song_match.song.note.Note) → None[source]

Make Cozmo play a note.

Parameters:note – The Note to play.
Returns:None
play_note_with_error(note: song_match.song.note.Note, sequence_length: int = 1) → Tuple[bool, song_match.song.note.Note][source]

Make Cozmo play a Note with a chance for error.

Parameters:
  • note – The Note to play.
  • sequence_length – The length of the sequence to play.
Returns:

Whether Cozmo played the correct note, and the Note he played.

Return type:

Tuple[bool, Note]

play_notes(notes: List[song_match.song.note.Note], with_error=False) → Tuple[bool, Union[NoneType, song_match.song.note.Note]][source]

Make Cozmo play a series of notes.

Parameters:
  • notes – The series of notes to play.
  • with_error – Whether to play the series of notes with a chance for error.
Returns:

Whether cozmo played the correct notes and the incorrect note he played if any.

Return type:

Tuple[bool, Union[None, Note]]

robot

Property for accessing Robot.

say_text(text: str) → cozmo.robot.SayText[source]

Wrapper method for say_text().

Returns:SayText
song

Property for accessing Song.

tap_cube(cube_id) → cozmo.anim.Animation[source]

Make Cozmo tap a cube.

Parameters:cube_idcube_id
Returns:Animation
turn_back_to_center(in_parallel=False) → None[source]

Turn Cozmo back to the center.

Parameters:in_parallel – Whether to do the action in parallel or wait until it’s completed.
Returns:None
turn_to_cube(cube_id: int) → None[source]

Make Cozmo turn in place until the specified cube is visible.

Parameters:cube_idcube_id to turn to.
Returns:None
world

Property for accessing world.

song_match.song_robot.random() → x in the interval [0, 1).