コード例 #1
0
ファイル: part1.php プロジェクト: ultramega/adventofcode2015
 private static function takeTurns(GameState $state, Spell $spell)
 {
     $state->applyEffects();
     if ($state->isBossDead()) {
         return true;
     }
     if (!$state->isSpellAvailable($spell)) {
         return false;
     }
     $state->castSpell($spell);
     $state->applyEffects();
     if ($state->isBossDead()) {
         return true;
     }
     $state->takeDamage();
     if ($state->isPlayerDead()) {
         return false;
     }
     return null;
 }
コード例 #2
0
ファイル: player.php プロジェクト: jerovetz/poker-player-kitt
 public function betRequest($game_state)
 {
     $gameState = GameState::fromArray($game_state);
     $myself = $gameState->getMyself();
     $myCards = $myself->getHand();
     $cardAnalizer = new CardAnalizer();
     $decision = new Decisions($gameState);
     if ($gameState->isPreFlop()) {
         if ($cardAnalizer->isHighPair($myCards)) {
             $bet = $myself->stack / 2;
             return (int) $bet;
         }
         if ($cardAnalizer->isPair($myCards)) {
             $callAmount = $this->call($gameState);
             return (int) $callAmount;
         }
         if (!$gameState->isSomeBodyRaised()) {
             $callAmount = $this->call($gameState);
             return (int) $callAmount;
         }
         $c1Rank = CardHelper::mapRankToValues($myCards[0]->rank);
         $c2Rank = CardHelper::mapRankToValues($myCards[1]->rank);
         if ($c1Rank > 10 || $c2Rank > 10) {
             $callAmount = $this->call($gameState);
             return (int) $callAmount;
         }
         return 0;
     } else {
         if ($cardAnalizer->IHavePair($gameState->getAllCards(), $gameState->getCommunityCards())) {
             $minBet = $this->betMinimumRaise($gameState);
             return (int) $minBet;
         }
         $rank = Rainman::getRank($gameState->getAllCards());
         $noService = array(0, 1, 2, 3);
         if (!in_array($rank, $noService)) {
             if (rand(0, 1)) {
                 $minBet = $this->betMinimumRaise($gameState);
                 return (int) $minBet;
             }
             $callAmount = $this->call($gameState);
             return (int) $callAmount;
         }
     }
     return 0;
 }
コード例 #3
0
ファイル: mainController.php プロジェクト: jgiunti/CeeLo
<?php

session_start();
if (!isset($_SESSION['userID'])) {
    header("Location:../login.html");
}
$sessionUser = $_SESSION['userID'];
require_once 'GameState.php';
$new = $_POST["new"];
if ($new == 1) {
    GameState::clearGameInProgress($sessionUser);
    echo 'success';
} else {
    $rows = GameState::checkGameInProgress($sessionUser);
    if ($rows > 0) {
        $state = new GameState(1);
        $turn = $state->turn;
        echo json_encode(array('continue', $turn));
    } else {
        echo 'error';
    }
}
コード例 #4
0
ファイル: index.php プロジェクト: Alegzandr/lamp_2
<?php

require_once "models/GameState.php";
session_start();
if (isset($_POST['reset'])) {
    unset($_SESSION['game_state']);
}
if (!isset($_SESSION['game_state'])) {
    $state = new GameState("Julien");
    $state->initialDeal();
    $_SESSION['game_state'] = $state;
} else {
    $state = $_SESSION['game_state'];
}
include "views/home.php";
コード例 #5
0
 public function getDecisions() : array
 {
     $decisions = parent::getDecisions();
     shuffle($decisions);
     return $decisions;
 }
コード例 #6
0
ファイル: gameController.php プロジェクト: jgiunti/CeeLo
<?php

session_start();
if (!isset($_SESSION['userID'])) {
    header("Location:../login.html");
}
$sessionUser = $_SESSION['userID'];
require_once 'GameState.php';
$d1 = $_POST['d1'];
$d2 = $_POST['d2'];
$d3 = $_POST['d3'];
$turn = $_POST['turn'];
$points = 0;
$dArray = array($d1, $d2, $d3);
sort($dArray);
$state = new GameState($sessionUser);
$lastRoll = $state->lastRoll;
$trip = $state->trip;
if ($dArray[0] == 1 && $dArray[1] == 2 && $dArray[2] == 3) {
    $res = 'lose';
} elseif ($dArray[0] == 4 && $dArray[1] == 5 && $dArray[2] == 6) {
    $res = 'win';
} else {
    if ($dArray[0] == $dArray[1] && $dArray[1] == $dArray[2]) {
        if ($lastRoll == 0) {
            $res = $dArray[2];
            $state->trip = 1;
        } else {
            if ($dArray[0] > $lastRoll) {
                $res = 'win';
                $state->trip = 0;
コード例 #7
0
ファイル: GameRequest.php プロジェクト: JohnWestwig/ChessWars
<?php

include "GameState.php";
//Get the parameters of the request:
$action = $_REQUEST["action"];
$details = $_REQUEST["details"];
$comID = $_REQUEST["comID"];
try {
    //echo "FAILURE|Foo";
    $dbFile = "GameInfo.txt";
    $gameState = new GameState($dbFile);
    $gameState->ProcessAction($comID, $action, $details);
    echo $gameState->ConstructOutputResponse($comID);
} catch (Exception $e) {
    echo "FAILURE|" . $e->getMessage();
}
コード例 #8
0
}
//populate an array of horses
$horses = array(new horse(1, "Alex", 61, 50, 1, 1, 1, 1), new horse(2, "Bob", 61, 50, 1, 1, 1, 2), new horse(3, "Maggie", 61, 50, 1, 1, 1, 3), new horse(4, "Sigboom", 61, 50, 1, 1, 2, 4), new horse(5, "Peter", 60, 50, 1, 1, 2, 5), new horse(6, "Janelle", 60, 50, 1, 1, 2, 6), new horse(7, "Ingrid", 60, 50, 1, 1, 1, 7), new horse(8, "Nea", 60, 50, 1, 1, 1, 1), new horse(9, "Sarah", 60, 50, 1, 1, 1, 2), new horse(10, "Christina", 60, 50, 1, 1, 2, 3), new horse(11, "Julianna", 59, 50, 1, 1, 2, 4), new horse(12, "Morgan", 59, 50, 1, 1, 2, 5), new horse(13, "Amanda", 59, 50, 1, 1, 2, 6), new horse(14, "Heather", 59, 50, 1, 1, 2, 7));
function initializeLaneScoreTree()
{
    $num_lengths_ahead_node = new DecisionTreeNode("num_lengths_ahead", [new Edge("0", 0, null), new Edge("1", 1, null), new Edge("2", 2, null), new Edge("3", 3, null), new Edge("4", 4, null), new Edge("5+", 5, null)]);
    $right_lane_num_turns_left_node = new DecisionTreeNode("num_turns_left", [new Edge("0", -0, $num_lengths_ahead_node), new Edge("1", -1, $num_lengths_ahead_node), new Edge("2", -2, $num_lengths_ahead_node)]);
    $left_lane_num_turns_left_node = new DecisionTreeNode("num_turns_left", [new Edge("0", 0, $num_lengths_ahead_node), new Edge("1", 1, $num_lengths_ahead_node), new Edge("2", 2, $num_lengths_ahead_node)]);
    $where_is_lane_node = new DecisionTreeNode("where_is_lane", [new Edge("left", 0, $left_lane_num_turns_left_node), new Edge("right", 0, $right_lane_num_turns_left_node), new Edge("same", 0, $num_lengths_ahead_node)]);
    $space_in_lane_node = new DecisionTreeNode("space_in_this_lane", [new Edge("yes", 0, $where_is_lane_node), new Edge("no", null, null)]);
    return new DecisionTree($space_in_lane_node);
}
// Set up the initial snapshot
$track = new Track(3000, 2000, 80, 840, 2160, 840, 840, 420.169, 20);
$lane_score_tree = initializeLaneScoreTree();
$game_state = new GameState($horses, $track);
$animation_array = array();
$done = false;
$ts = 1;
$ts_scale = 0.01;
$total_distance = 840 + 1320;
$final_placement = 0;
while (!$done) {
    $snapshot = new snapshot($ts, $track);
    $dt = ($snapshot->get_ts() - $game_state->get_ts()) * $ts_scale;
    $num_horses_finished = 0;
    foreach ($horses as $horse) {
        // gather some useful info into one place
        $horseid = $horse->get_id();
        /** @var horse_details $horse_detail */
        $horse_detail = $game_state->get_details($horseid);