@ -75,7 +75,8 @@ fn printHand(state: &GameState) {
}
}
fn deal ( human : usize , trump : Option < Suit > ) {
fn deal ( human : usize , trump : Option < Suit > ) -> ( u8 , u8 ) {
let player_names : [ & str ; 4 ] = [ "South" , "West" , "North" , "East" ] ;
match trump {
Some ( x ) = > println ! ( "The trump is {:?}" , x ) ,
None = > println ! ( "There is no trump" ) ,
@ -115,10 +116,14 @@ fn deal(human: usize, trump: Option<Suit>) {
. unwrap ( ) ;
let mut player : usize = 0 ;
let mut ais : [ Option < Node > ; 4 ] = [ None , None , None , None ] ;
for _ turn in 0 . . 52 {
for turn in 0 . . 52 {
let card_played : Card = if player = = human {
// we'll do the other stuff later
printHand ( & states [ player as usize ] ) ;
match & states [ player as usize ] . trick [ 0 ] {
Some ( x ) = > println ! ( "The suit led is {:?}." , x . suit ) ,
None = > println ! ( "Your lead." ) ,
}
println ! ( "What do you play? " ) ;
readCard ( )
} else {
@ -166,7 +171,11 @@ fn deal(human: usize, trump: Option<Suit>) {
}
}
ais [ player ] = Some ( node ) ;
println ! ( "{} played {}!" , player , numToCard ( best_move as u8 ) ) ;
println ! (
"{} played {}!" ,
player_names [ ( ( player + 4 ) - human ) % 4 ] ,
numToCard ( best_move as u8 )
) ;
numToCard ( best_move as u8 )
} ;
for i in 0 . . 4 {
@ -184,9 +193,64 @@ fn deal(human: usize, trump: Option<Suit>) {
states [ i ] = state_transit ( & states [ i ] , card_played ) ;
}
player = states [ 0 ] . player as usize ;
if states [ 0 ] . trick [ 0 ] . is_none ( ) {
if turn ! = 51 {
println ! ( "New trick." ) ;
}
println ! (
"Now N-S have {} tricks, and E-W have {}." ,
states [ 0 ] . tricksWonBy0 ,
( 13 - states [ 0 ] . sizes [ 0 ] ) - states [ 0 ] . tricksWonBy0
) ;
}
}
if ( states [ 0 ] . tricksWonBy0 > 6 ) {
println ! (
"Yay! Your team won more than 6 tricks -- in fact, you won {}. So you get {} points!" ,
states [ 0 ] . tricksWonBy0 ,
states [ 0 ] . tricksWonBy0 - 6
) ;
( states [ 0 ] . tricksWonBy0 - 6 , 0 )
} else {
println ! ( "Aw... The other team won more than 6 tricks -- they won {}. Therefore, they get {} points." , 13 - states [ 0 ] . tricksWonBy0 , ( 7 - states [ 0 ] . tricksWonBy0 ) ) ;
( 0 , 7 - states [ 0 ] . tricksWonBy0 )
}
}
fn game ( ) {
println ! ( "Let's play Whist! You are South, and your partner is North. Your opponents are West and East." ) ;
let player_names : [ & str ; 4 ] = [ "South" , "West" , "North" , "East" ] ;
let trumpSeq = [
Some ( Suit ::Hearts ) ,
Some ( Suit ::Spades ) ,
Some ( Suit ::Diamonds ) ,
Some ( Suit ::Clubs ) ,
None ,
] ;
let mut points = ( 0 , 0 ) ;
let mut first = random ::< usize > ( ) % 4 ;
let mut trump = 0 ;
while points . 0 < 7 & & points . 1 < 7 {
println ! ( "N-S has {} points, E-W has {}." , points . 0 , points . 1 ) ;
println ! ( "New deal! {} goes first." , player_names [ first ] ) ;
let new_points = deal ( 4 - first , trumpSeq [ trump ] ) ;
points = ( points . 0 + new_points . 0 , points . 1 + new_points . 1 ) ;
trump + = 1 ;
trump % = 5 ;
first + = 1 ;
first % = 4 ;
}
if points . 0 > = 7 {
println ! ( "Congratulations! You won!" ) ;
} else {
println ! ( "Sorry... you lose." ) ;
}
println ! (
"N-S finished with {} points, E-W with {}." ,
points . 0 , points . 1
) ;
}
fn rankOf ( c : Card ) -> u8 {
c . rank
}
@ -645,7 +709,10 @@ fn simulate(state: &GameState, hands: &mut [Vec<u8>; 4]) -> i8 {
}
fn main ( ) {
deal ( 0 , Some ( Suit ::Hearts ) ) ;
//deal(0, Some(Suit::Hearts));
game ( ) ;
return ;
let mut played = bitarr ! ( 0 ; 52 ) ;
let mut node = new_node ( GameState {
player : 0 ,