garak/pokerino 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

garak/pokerino

最新稳定版本:v0.3.0

Composer 安装命令:

composer require garak/pokerino

包简介

A PHP library to manage Poker card games

README 文档

README

License PHP Version Require Maintainability Code Coverage

Introduction

This library offers PHP classes for building a Poker card game:

  • Game (abstract, needs to be extended)
  • Player (abstract, needs to be extended)
  • Hand — evaluates a poker hand
  • PokerRank — identifies the best hand from a set of cards

Hand and PokerRank work with any number of cards and are not tied to a specific poker variant. Game::deal() is configurable for different dealing styles (see Usage). Game::winner() assumes a community-card structure (e.g. Texas Hold'em, Omaha) and should be overridden for variants without community cards (e.g. 5-Card Draw, 7-Card Stud).

Supported hand rankings (highest to lowest)

Rank Name
1 Royal Flush
2 Straight Flush
3 Four of a Kind
4 Full House
5 Flush
6 Straight
7 Three of a Kind
8 Two Pair
9 Pair
10 High Card

Installation

Run composer require garak/pokerino.

Usage

Texas Hold'em example

<?php

require 'vendor/autoload.php';

use App\Game;    // your Game class, extending \Garak\Pokerino\Game
use App\Player;  // your Player class, extending \Garak\Pokerino\Player

$game = new Game();
$game->join(new Player('Marty McFly'));
$game->join(new Player('Biff Tannen'));
$game->join(new Player('Emmett Brown'));

// Deal 2 hole cards to each player + 5 community cards (Texas Hold'em defaults)
$game->deal();

// Retrieve all hands (player hands first, community hand last)
$hands = $game->getHands();

// Evaluate a single hand
$hand = $hands[0];
echo $hand->getPoint();          // e.g. "Flush"
echo $hand->getHigh();           // highest relevant card
echo $hand->getKicker();         // best side card
echo $hand->getHandStrength();   // numeric rank: 1 (Royal Flush) … 10 (High Card)

// Determine the winner (combines each player's hole cards with community cards)
$winner = $game->winner();
echo $winner; // player name

Other variants

deal() accepts custom parameters to support different dealing styles:

$game->deal(5, 0);  // 5-Card Draw: 5 hole cards, no community cards
$game->deal(4, 5);  // Omaha: 4 hole cards + 5 community cards
$game->deal(2, 5);  // Texas Hold'em (default)

Note: winner() assumes a community-card structure. For variants without community cards, override it in your Game subclass.

Evaluating a hand directly

use Garak\Card\Card;
use Garak\Pokerino\Hand;

$cards = [
    Card::fromRankSuit('Ac'),
    Card::fromRankSuit('Kc'),
    Card::fromRankSuit('Qc'),
    Card::fromRankSuit('Jc'),
    Card::fromRankSuit('Tc'),
    Card::fromRankSuit('2s'),
    Card::fromRankSuit('7d'),
];

$hand = new Hand($cards);
echo $hand->getPoint();        // "Royal Flush"
echo $hand->getHandStrength(); // 1

Credits

The original idea was developed with davidino.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2024-01-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固