用PHP实现一个关于德州扑克算法的程序(四):代码

本文介绍了使用PHP实现德州扑克算法的程序,包括程序主入口、Cards类、Player类和核心算法类Table类。文章提供了运行显示效果,并指出剩余10%的内容如同花顺判断等虽简单,但已完成大部分算法挑战。
摘要由CSDN通过智能技术生成

程序主入口

<?php
include "Table.class.php";
//显示函数
function pre($str){
   
    echo '<pre>';
    print_r($str);
    echo '</pre>';
}

//创建扑克牌
$c=new Cards();
//初始化玩家数量
$table=new Table(2,$c->Cards);

扑克牌类 Cards.class.php

class Cards{
   
    public $Cards=array();

    function __construct()
    {
   
        $this->Cards=$this->createCards();
        shuffle($this->Cards);
    }
    private function createCards()
    {
   
        $cards=array();
        $suit=array("H","S","D","C");
        $p=array("T","J","Q","K","A");

        for($i=0;$i<count($suit);$i++){
            for($j=2;$j<=9;$j++){
                $cards[]=$suit[$i].$j;
            }
            for($k=0;$k<count($p);$k++){
                $cards[]=$suit[$i].$p[$k];
            }
        }
        return $cards;
    }
}

玩家类 Player.class.php

class Player{
   

    public $score=0;
    public $CardInHand=array();

    function __construct($cards)
    {
   
        $this->getCardInHand($cards);
    }

    private function getCardInHand($cards){
   
        $randkey=array_rand($cards,2);
        $this->CardInHand[]=$cards[$randkey[0]];
        $this->CardInHand[]=$cards[$randkey[1]];
        return $this->CardInHand;
    }

}

牌桌类(核心算法类)Table.class.php

include "Cards.class.php";
include "Player.class.php";

class  Table{
   

    public $players=array();
    public $tablecards=array();

    function __construct($num,$cards)
    {
   
        for($i=0;$i<$num;$i++){
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值