NIVEL 2 - A (mensaje 1)
Este Script es el manejador, el que lanza todo. Este es el que se puede tocar para hacer las pruebas.
Código PHP:
<?php
require_once 'Baraja.php';
require_once 'Carta.php';
require_once 'Algoritmo.php';
require_once 'ManoJugador.php';
require_once 'Poker.php';
header('Content-Type: text/html; charset=UTF-8');
/* * *************************
* MODO REAL (CARTAS DE MANERA ALEATORIA (2 PLAYERS))
* ************************* */
$baraja = new Baraja();
$mazo = $baraja->getBaraja();
$poker1 = new Poker();
$player1 = array($mazo[0], $mazo[2], $mazo[4], $mazo[6], $mazo[8]);
$player2 = array($mazo[1], $mazo[3], $mazo[5], $mazo[7], $mazo[9]);
$jugadaPlayer1 = $poker1->jugada($player1);
print "<br>MODO REAL(player 1) --> {$jugadaPlayer1}";
$ganador = $poker1->partida($player1, $player2);
print "<br>MODO REAL(ganador): {$ganador}";
print "<br><br>--------------------------<br><br>";
/* * *************************
* MODO DEBUG (CARTAS ELEGIDAS POR EL USER (2 PLAYERS))
* ************************* */
$poker2 = new Poker();
$barajaDebug1 = array(new Carta("4", "c"), new Carta("4", "p"), new Carta("3", "c"), new Carta("3", "c"), new Carta("a", "c"));
$barajaDebug2 = array(new Carta("4", "p"), new Carta("4", "c"), new Carta("3", "p"), new Carta("3", "p"), new Carta("5", "p"));
$jugadaDebug = $poker2->jugada($barajaDebug1);
print "MODO DEBUG(player 1) --> {$jugadaDebug}";
$ganadorDebug = $poker2->partida($barajaDebug1, $barajaDebug2);
print "<br>MODO DEBUG(ganador player1): {$ganadorDebug}";
?>
La clase Poker:
Código PHP:
<?php
class Poker {
public function Poker() {
}
public function jugada($cartas) {
$mano = new ManoJugador($cartas);
if ($mano->getBoolEscaleraReal()) {
$result = "Escalera real";
} elseif ($mano->getBoolEscaleraColor()) {
$result = "Escalera de color";
} elseif ($mano->getBoolPoker()) {
$result = "Póker";
} elseif ($mano->getBoolFull()) {
$result = "Full";
} elseif ($mano->getBoolColor()) {
$result = "Color";
} elseif ($mano->getBoolEscalera()) {
$result = "Escalera";
} elseif ($mano->getBoolTrio()) {
$result = "Trío";
} elseif ($mano->getBoolDoblesParejas()) {
$result = "Dobles parejas";
} elseif ($mano->getBoolPareja()) {
$result = "Pareja";
} else {
$result = "Carta alta";
}
return $result;
}
public function partida($cartas1, $cartas2) {
$ordenJugadas = array("Carta alta" => 0, "Pareja" => 1, "Dobles parejas" => 2, "Trío" => 3, "Escalera" => 4,
"Color" => 5, "Full" => 6, "Póker" => 7, "Escalera de color" => 8, "Escalera real" => 9);
$manoPlayer1 = new ManoJugador($cartas1);
$manoPlayer2 = new ManoJugador($cartas2);
if ($this->jugada($cartas1) == $this->jugada($cartas2)) {
//si es la misma jugada ver quien tiene la carta mas alta
if ($this->jugada($cartas1) != "Escalera real") {
switch ($this->jugada($cartas1)) {
case "Escalera de color":
$player1 = $manoPlayer1->getEscaleraColor();
$player2 = $manoPlayer2->getEscaleraColor();
$key = "max";
break;
case "Póker":
$player1 = $manoPlayer1->getPoker();
$player2 = $manoPlayer2->getPoker();
$key = "val";
break;
case "Full":
$player1 = $manoPlayer1->getFull();
$player2 = $manoPlayer2->getFull();
$key = "val";
break;
case "Color":
$player1 = $manoPlayer1->getColor();
$player2 = $manoPlayer2->getColor();
$key = "val";
break;
case "Escalera":
$player1 = $manoPlayer1->getEscalera();
$player2 = $manoPlayer2->getEscalera();
$key = "max";
break;
case "Trío":
$player1 = $manoPlayer1->getTrio();
$player2 = $manoPlayer2->getTrio();
$key = "val";
break;
case "Dobles parejas":
$player1 = $manoPlayer1->getParejasODobles();
$player2 = $manoPlayer2->getParejasODobles();
$key = "val";
break;
case "Pareja":
$player1 = $manoPlayer1->getParejasODobles();
$player2 = $manoPlayer2->getParejasODobles();
$key = "val";
$jugada = "pareja";
break;
case "Carta alta":
$player1 = $manoPlayer1->getCartaAlta();
$player2 = $manoPlayer2->getCartaAlta();
$key = "val";
$jugada = "cartAlta";
break;
default:
return 0;
}
if (!is_array($player1[$key])) {
if ($player1[$key] > $player2[$key]) {
return 1;
} elseif ($player1[$key] < $player2[$key]) {
return -1;
} else {
if (isset($jugada) && $jugada == "pareja") {
$max = 3;
$cont = 0;
$excp = array(array($player1[$key]), array($player2[$key]));
do {
$alta1 = $manoPlayer1->getCartaAlta($excp[0]);
$alta2 = $manoPlayer2->getCartaAlta($excp[1]);
$excp[0][] = $alta1['val'];
$excp[1][] = $alta2['val'];
$cont += 1;
} while (($alta1 == $alta2) && ($cont != $max));
if ($alta1 == $alta2) {
return 0;
} elseif ($alta1 > $alta2) {
return 1;
} else {
return -1;
}
} elseif (isset($jugada) && $jugada == "cartAlta") {
$max = 5;
$cont = 1;
$excp = array(array($player1[$key]), array($player2[$key]));
do {
$alta1 = $manoPlayer1->getCartaAlta($excp[0]);
$alta2 = $manoPlayer2->getCartaAlta($excp[1]);
$excp[0][] = $alta1['val'];
$excp[1][] = $alta2['val'];
$cont += 1;
} while (($alta1 == $alta2) && ($cont != $max));
if ($alta1 == $alta2) {
return 0;
} elseif ($alta1 > $alta2) {
return 1;
} else {
return -1;
}
} else {
return 0;
}
}
} else {
$play1 = 0;
$play2 = 0;
if ($player1[$key][0] > $player2[$key][0]) {
$play1 += 1;
} elseif ($player1[$key][0] < $player2[$key][0]) {
$play2 += 1;
}
if ($player1[$key][1] > $player2[$key][1]) {
$play1 += 1;
} elseif ($player1[$key][1] < $player2[$key][1]) {
$play2 += 1;
}
if ($play1 > $play2) {
return 1;
} elseif ($play1 < $play2) {
return -1;
} else {
$excp = array(array($player1[$key][0], $player1[$key][1]), array($player2[$key][0], $player2[$key][1]));
$alta1 = $manoPlayer1->getCartaAlta($excp[0]);
$alta2 = $manoPlayer2->getCartaAlta($excp[1]);
if ($alta1 == $alta2) {
return 0;
} elseif ($alta1 > $alta2) {
return 1;
} else {
return -1;
}
}
}
} else {
return 0;
}
} elseif ($ordenJugadas[$this->jugada($cartas1)] > $ordenJugadas[$this->jugada($cartas2)]) {
return 1;
} else {
return -1;
}
}
}
?>