Class: TresRaya::DumbPlayer

Inherits:
Player
  • Object
show all
Defined in:
lib/tres_raya/dumb_player.rb

Instance Attribute Summary

Attributes inherited from Player

#mark

Instance Method Summary collapse

Methods inherited from Player

#initialize

Constructor Details

This class inherits a constructor from TresRaya::Player

Instance Method Details

#finish(final_board) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tres_raya/dumb_player.rb', line 8

def finish( final_board )
#      print final_board
  
  if final_board.won? == @mark
#        print "Congratulations, you win.\n\n"
win = 1
  elsif final_board.won? == " "
#        print "Tie game.\n\n"
win = 0
  else
#        print "You lost tic-tac-toe?!\n\n"
win = -1
  end
  win
end

#move(board) ⇒ Object



3
4
5
6
# File 'lib/tres_raya/dumb_player.rb', line 3

def move( board )
  moves = board.moves
  moves[rand(moves.size)]
end