Coder Social home page Coder Social logo

card_game's Introduction

CardGame

Ruby utility library for various card games.

Really just me playing around with design ideas.

Synopsis

You can compare poker hands.

require 'card_game/poker'

include CardGame

Poker.classify(Hand.build("10H JH QH KH AH")) >
Poker.classify(Hand.build("AH AD AS AC KH"))
# => true

You can calculate winning cards in Five Hundred tricks.

require 'card_game/five_hundred'

FiveHundred.winning_card(Trick.new(
  cards: Hand.build("10S JD AH 10D"),
  trump: Suit.hearts,
))
# => Card.from_string("JD")

FiveHundred.winning_card(Trick.new(
  cards: Card.array_from_string("10S JD AH 10D"),
  trump: Suit.clubs,
))
# => Card.from_string("10S")

You can play a simple game of Five Hundred. (This is experimental and incomplete.)

require 'card_game/five_hundred'

game = CardGame::FiveHundred.play(players: 4)

players = game.state.players
hand = -> player { game.state.hands.fetch(player) }

game.apply players[0].bid(6, CardGame::Suit.hearts)
game.apply players[1].pass
game.apply players[2].bid(7, CardGame::Suit.hearts)
game.apply players[3].pass
game.apply players[0].pass
game.apply players[1].pass

game.apply players[2].kitty(hand.(players[2]).take(3))

(0..9).each do
  i = players.index(game.state.priority)
  game.apply players[(i+0) % 4].play(hand.(players[(i+0) % 4])[0])
  game.apply players[(i+1) % 4].play(hand.(players[(i+1) % 4])[0])
  game.apply players[(i+2) % 4].play(hand.(players[(i+2) % 4])[0])
  game.apply players[(i+3) % 4].play(hand.(players[(i+3) % 4])[0])
end

require 'pp'
pp game.state

There are also silly monkeypatches you probably don't want to use in real life, but make for fun READMEs.

require 'card_game/core_ext'

FiveHundred.winning_card(Trick.new(
  cards: [ "A"., 5., 10., "A". ],
  trump: Suit.,
))
# => Card.from_string("AD")

Developing

bundle install
bin/test

card_game's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

card_game's Issues

About the course at pluralsight

Sorry to raise ticket here directly, I feel it is hard to do that in pluralsight. I will recommend to upload the videos to Udemy, which you get more viewers.

I am current learning rspec with your course "Testing Ruby Applications with RSpect", and really thanks for giving me the chance to catch it up with this course.

But I have some issues with it.

When run with the code in some videos, I can't make it run properly. So could you please provide the codes for each video, currently I download the code zip file, it has codes only for each module, not each video.

Second, when I learn at "Gatting Started" --> "Deep Dive: Examples and example Groups", I run the command "bin/play", it is fail with below error:

$ bin/play
Could not find bank account, you cannot play

I understand I need create a new folder /tmp/bank-accounts, but what file and the file format I need provide?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.