Skip to content

Commit

Permalink
Merge pull request #2 from bradleycwojcik/release/v0.1.0
Browse files Browse the repository at this point in the history
Release/v0.1.0
  • Loading branch information
boldandbrad authored Jul 6, 2020
2 parents 9bae74b + 71ed9b6 commit b44ca35
Show file tree
Hide file tree
Showing 14 changed files with 415 additions and 252 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.iml
.project
.vscode
.markdownlint.yaml

# os
.DS_Store
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2020-07-06

### Added

- `euchre play` - Four computer players can successfully play a full game of
euchre together, making random decisions (within the rules)
- `euchre --version` - Check current installed version
- `euchre --help` - Print out cli usage
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
# euchre-cli
# euchre-cli :spades:

Play euchre in your terminal.

## Installation

### macOS

```zsh
coming soon
```

### Windows

```cmd
coming soon
pip install euchrecli
```

## Usage

> Coming soon
```zsh
euchre play
```

## Planned Features

### Release 1ish
### Release 1.x

* Ability to enter username
* Ability to play through a complete game of euchre with 3 cpus
Expand All @@ -31,9 +25,10 @@ coming soon
* Game debug logs
* Euchre rules overview
* Output euchre-cli version
* Usage documentation
* Published to pypi

### Release 2ish
### Release 2.x

* Ability to save user configs
* Ability to revert to default configs
Expand All @@ -46,7 +41,6 @@ coming soon
* Ability to adjust speed of cpu decision making
* Shell output coloring and emojis
* Choose trump suit from suits in hand only mode
* Install with homebrew on mac and linux

### Future

Expand All @@ -59,16 +53,29 @@ coming soon
* 'Nines and tens' mode
* 'Ace no face' mode
* Three handed euchre mode
* Install with Chocolatey on windows
* Install with homebrew on mac and linux ?
* Install with Chocolatey on windows ?

## Changelog

[Changelog](./CHANGELOG.md)

## Contribute
## Development

[Contributing](./CONTRIBUTING.md)

```zsh
git clone https://github.com/bradleycwojcik/euchre-cli
```

```zsh
pip install .
```

```zsh
euchre --help
```

## License

[MIT License](./LICENSE)
2 changes: 1 addition & 1 deletion euchrecli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# release version
version = '0.0.1'
version = '0.1.0'
163 changes: 163 additions & 0 deletions euchrecli/commands/play.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@

import click

from euchrecli.util.card_util import Card, Suit
from euchrecli.util.deck_util import create_deck, deal_hand
from euchrecli.util.player_util import Team, Player, rotate_dealer, \
rotate_trick_order
from euchrecli.util.rule_util import valid_play, trick_winner, hand_winner


@click.command(help='Start a new euchre game.')
def play():
setup()


def setup():
"""Setup players."""
# TODO: implement setup from user input

# TODO: implement random team assignment and order
teams = [
Team('Team 1'),
Team('Team 2')
]
players = [
Player('Mitch', teams[0]),
Player('Lena', teams[1]),
Player('Bradley', teams[0]),
Player('Morgan', teams[1])
]
players[-1].is_dealer = True
print(players)
print(f'{players[-1].name} is dealer')

# start game
game(players, teams)


def game(players: [Player], teams: [Team]):
"""Start game and manage team scores."""
# play hands until the game is won
game_won = False
hand_number = 1
while not game_won:
# deal and play hand
hand(hand_number, players)

# determine hand winner
winning_team = hand_winner(teams)

for team in teams:
print(f'{team.name}: {team.game_score}')

# check if winning team has won the game
if winning_team.game_score >= 10:
game_won = True
print(f'{winning_team} wins!')
else:
# increment hand number
hand_number += 1

# rotate dealer to the left
rotate_dealer(players)
print(f'New Dealer: {players[-1].name}')

# TODO: implement play again logic


def hand(number: int, players: [Player]) -> None:
"""Deal and play a hand."""
print(f'\nPlay Hand {number}\n')
trump_suit = None

# set trump suit
while not trump_suit:
# create and shuffle deck then deal new hand
deck = create_deck()
deal_hand(players, deck)

# set trump suit
trump_suit = set_trump_suit(players, deck)

# TODO: remove next three lines
for player in players:
print(f'{player.name}\'s hand: {player.hand}')
print(f'Deck: {deck}')

print(f'Trump suit is {trump_suit}')

# play 5 tricks
for _ in range(5):
# play trick and determine winner
played_cards = trick(players, trump_suit)
trick_winner(players, played_cards, trump_suit)

# TODO: remove next two lines
for player in players:
print(f'{player.name}\'s hand: {player.hand}')

# adjust play order based on winner of previous trick
rotate_trick_order(players)


def set_trump_suit(players: [Player], deck: [Card]) -> Suit:
"""Set trump suit for the current hand."""
print('Set trump suit')
# dealer flips card
face_up_card = deck[0]
deck.pop(0)

face_up_suit = face_up_card.suit

print(f'Face up card is {face_up_card}')

trump_suit = None

# pickup round
for player in players:
if not trump_suit:
if player.call_pick_up(face_up_card):
print(f'{player.name} says pick it up')
# capture trump suit and team that called for it
trump_suit = face_up_card.suit
player.team.called_trump = True

# dealer picks up face up card
replaced_card = players[3].pick_up_card(face_up_card)
deck.append(replaced_card)
else:
print(f'{player.name} passes')

# call round
if not trump_suit:
print(f'Trump suit cannot be {face_up_suit}')
for player in players:
if not trump_suit:
candidate_suit = player.call_trump_suit(face_up_suit)
print(f'{player.name} proposes {candidate_suit}')
if candidate_suit != face_up_suit:
trump_suit = candidate_suit
player.team.called_trump = True
else:
print(f'{player.name} passes')

return trump_suit


def trick(players: [Player], trump_suit: Suit) -> [Card]:
"""Players take turns playing cards in a trick."""
print('\nPlay Trick\n')
played_cards = []
for player in players:
print(f'{player.name}\'s play')
card_to_play = player.play_card(played_cards, trump_suit)
while not valid_play(card_to_play, player.hand, played_cards,
trump_suit):
card_to_play = player.play_card(played_cards, trump_suit)

played_cards.append(card_to_play)
player.remove_card(card_to_play)

print(f'Played cards: {played_cards}')
return(played_cards)
11 changes: 8 additions & 3 deletions euchrecli/euchre.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import click

from euchrecli.game import setup
from euchrecli.commands.play import play

@click.command()

@click.group()
@click.version_option()
def cli():
setup()
pass


cli.add_command(play, 'play')


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit b44ca35

Please sign in to comment.