Skip to content

EteimZ/whot

Repository files navigation

WHOT is an implementation of the Whot! game. It is an engine that implements all the necessary logic to implement your whot game.

Installation

WHOT is implemented in Python. You can easily install it from PyPI using pip:

pip install whot

Getting Started

The engine's API simulates how the actual whot game is played.

First you need to import the library:

from whot import Whot 

Then create an instance of the engine:

game = Whot()

Call the start_game method to begin the game:

game.start_game()

When the game is started, you can view the current state of the game with the game_state method.

game.game_state()

This returns:

{'current_player': 'player_1',
 'pile_top': 3 CIRCLE,
 'players': {'player_1': [4 CIRCLE, 13 CROSS, 4 STAR, 2 TRIANGLE],
             'player_2': [5 STAR, 10 CIRCLE, 1 SQUARE, 20 WHOT]}}

The game state has the following parameters:

  • current_player: The player who's turn it is.
  • pile_top: The card on the top of the pile.
  • players: A dictionary that contains all the players as keys and their cards as values

If you wish to get the view of a particular player, you can call the view method and specify the player's ID.

game.view('player_1')

This returns:

{'current_player': 'player_1',
 'pile_top': 3 CIRCLE,
 'players': {'player_1': [4 CIRCLE, 13 CROSS, 4 STAR, 2 TRIANGLE],
             'player_2': 4}}

Now, with this, we can begin playing. To play a card, you can use the play method to select the index of the current player's card, which in this case is player_1.

game.play(0)

This plays the first card of the player. When this method is called, the state of the engine updates:

{'current_player': 'player_2',
 'pile_top': 4 CIRCLE,
 'players': {'player_1': [13 CROSS, 4 STAR, 2 TRIANGLE],
             'player_2': [5 STAR, 10 CIRCLE, 1 SQUARE, 20 WHOT]}}

The second player, player_2, plays their second card.

game.play(1)

This also updates the state of the engine again:

{'current_player': 'player_1',
 'pile_top': 10 CIRCLE,
 'players': {'player_1': [13 CROSS, 4 STAR, 2 TRIANGLE],
             'player_2': [5 STAR, 1 SQUARE, 20 WHOT]}}

It's player_1's turn again, but they don't have a playable card, so they have to go to market using the market method.

game.market()

This adds an additional card to player one and switches the turn to player 2:

{'current_player': 'player_2',
 'pile_top': 10 CIRCLE,
 'players': {'player_1': [13 CROSS, 4 STAR, 2 TRIANGLE, 1 CROSS],
             'player_2': [5 STAR, 1 SQUARE, 20 WHOT]}}

Player two also doesn't have a playable card, but they have a whot card, so they play it:

game.play(2)

This puts the game in request mode. In request mode, the player who played the whot card can request any card suit of their choice using the request method.

game.request('square')

Player two requests a square. Player one doesn't have it, so they have to go to market.

Go through the documentation to learn more.

Contributions

This code base is open to contributions. To contribute, check out the issues of the repo. Pick an issue you want to resolve and drop a comment to express your interest in resolving the issue. If there's no issue, you can create an issue that you can resolve yourself or let someone else resolve it.

If you want to contribute, first fork the repo. Make your changes to your fork, then open a pull request (PR).

About

An implementation of the whot card game.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages