game-tictactoe-alu3299 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +25 -0
- data/README.md +18 -0
- data/Rakefile +49 -0
- data/bin/game_tictactoe.rb +14 -0
- data/bin/game_tictactoe_players.rb +28 -0
- data/game-tictactoe-alu3299.gemspec +24 -0
- data/lib/game-tictactoe-alu3299.rb +12 -0
- data/lib/tictactoe/dumbplayer.rb +12 -0
- data/lib/tictactoe/humanplayer.rb +34 -0
- data/lib/tictactoe/minimaxplayer.rb +73 -0
- data/lib/tictactoe/player.rb +18 -0
- data/lib/tictactoe/smartplayer.rb +48 -0
- data/lib/tictactoe/tictactoe.rb +140 -0
- data/lib/tictactoe/version.rb +5 -0
- data/spec/dumbplayer_spec.rb +15 -0
- data/spec/humanplayer_spec.rb +15 -0
- data/spec/minimaxplayer_spec.rb +15 -0
- data/spec/smartplayer_spec.rb +15 -0
- data/test/tc_dumbplayer.rb +16 -0
- data/test/tc_humanplayer.rb +16 -0
- data/test/tc_minimaxplayer.rb +16 -0
- data/test/tc_smartplayer.rb +16 -0
- metadata +144 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# File : Guardfile
|
2
|
+
|
3
|
+
# A sample Guardfile
|
4
|
+
# More info at https://github.com/guard/guard#readme
|
5
|
+
|
6
|
+
guard 'rspec' do
|
7
|
+
watch(%r{^spec/.+_spec\.rb$})
|
8
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
9
|
+
watch('spec/spec_helper.rb') { "spec" }
|
10
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Free Documentation License
|
2
|
+
Version 0.0.1, 8 December 2012
|
3
|
+
|
4
|
+
Copyright (c) 2012 mdbgalvan
|
5
|
+
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies of this
|
7
|
+
license document, but changing it is not allowed.
|
8
|
+
|
9
|
+
PREAMBLE
|
10
|
+
|
11
|
+
The purpose of this License is to make a manual, textbook, or other
|
12
|
+
functional and useful document "free" in the sense of freedom: to assure
|
13
|
+
everyone the effective freedom to copy and redistribute it, with or
|
14
|
+
without modifying it, either commercially or noncommercially. Secondarily,
|
15
|
+
this License preserves for the author and publisher a way to get credit
|
16
|
+
for their work, while not being considered responsible for modifications
|
17
|
+
made by others.
|
18
|
+
|
19
|
+
We have designed this License in order to use it for manuals for free
|
20
|
+
software, because free software needs free documentation: a free program
|
21
|
+
should come with manuals providing the same freedoms that the software does.
|
22
|
+
But this License is not limited to software manuals; it can be used for
|
23
|
+
any textual work, regardless of subject matter or whether it is published
|
24
|
+
as a printed book. We recommend this License principally for works whose
|
25
|
+
purpose is instruction or reference.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
**Autora:** *María D. Batista Galván*
|
2
|
+
**Fecha:** *Sábado 8 de Diciembre de 2012*
|
3
|
+
**Asignatura:** *Lenguajes y Paradigmas de la Programación.*
|
4
|
+
**Práctica:** **Laboratorio 10 :** *Creación de una Gema - Segunda Parte (Bundler)*
|
5
|
+
|
6
|
+
##Pasos
|
7
|
+
|
8
|
+
En dicha asignatura y para esta novena práctica se debía realizar los siguientes pasos:
|
9
|
+
|
10
|
+
Considere el desarrollo de una aplicación para jugar al **tres en raya** de la práctica anterior.
|
11
|
+
El objetivo de esta práctica es la construcción y publicación de una Gema en Ruby para la el juego de tres en raya. Para ello se ha de utilizar la herramienta **[Bundler](http://gembundler.com/)**.
|
12
|
+
1. Desarrollar un método para hacer que dos jugadores arbitrarios compitan.
|
13
|
+
2. Desarrollar un jugador minimax.
|
14
|
+
3. Construir la gema.
|
15
|
+
`gem build`
|
16
|
+
4. Considerar su publicacion.
|
17
|
+
`gem push`
|
18
|
+
5. Indique la URL del repositorio github o bitbucket que ha desarrollado.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + 'lib'
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
desc "Run TicTacToe game vs smart player"
|
10
|
+
task :smart do
|
11
|
+
sh "ruby -Ilib bin/game_tictactoe.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Run TicTacToe game vs dumb player"
|
15
|
+
task :dumb do
|
16
|
+
sh "ruby -Ilib bin/game_tictactoe.rb -d"
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Run TicTacToe game vs minimax player"
|
20
|
+
task :minimax do
|
21
|
+
sh "ruby -Ilib bin/game_tictactoe.rb -m"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Run rspec with --format documentation"
|
25
|
+
task :doc do
|
26
|
+
sh "rspec -Ilib spec/*.rb --format documentation --color"
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Run HumanPlayer tests"
|
30
|
+
task :hp_test do
|
31
|
+
sh "ruby -Ilib test/tc_humanplayer.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Run SmartPlayer tests"
|
35
|
+
task :sp_test do
|
36
|
+
sh "ruby -Ilib test/tc_smartplayer.rb"
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Run DumbPlayer tests"
|
40
|
+
task :dp_test do
|
41
|
+
sh "ruby -Ilib test/tc_dumbplayer.rb"
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Run TicTacToe by specifying two different players"
|
45
|
+
task :player, :x_player, :o_player do |player, args|
|
46
|
+
x_player = args[:x_player] || 'human'
|
47
|
+
o_player = args[:o_player] || 'minimax'
|
48
|
+
sh "ruby -Ilib bin/game_tictactoe_players.rb #{x_player} #{o_player}"
|
49
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# File : game_tictactoe.rb
|
2
|
+
|
3
|
+
require "game-tictactoe-alu3299"
|
4
|
+
|
5
|
+
if __FILE__ == $0
|
6
|
+
if ARGV.size > 0 and ARGV[0] == "-d"
|
7
|
+
game = Tictactoe::Game.new Tictactoe::HumanPlayer, Tictactoe::DumbPlayer
|
8
|
+
elseif ARGV.size > 0 and ARGV[0] == "-m"
|
9
|
+
game = Tictactoe::Game.new Tictactoe::HumanPlayer, Tictactoe::MinimaxPlayer
|
10
|
+
else
|
11
|
+
game = Tictactoe::Game.new Tictactoe::HumanPlayer, Tictactoe::SmartPlayer
|
12
|
+
end
|
13
|
+
game.play
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# File : game_tictactoe_players.rb
|
2
|
+
|
3
|
+
require "game-tictactoe-alu3299"
|
4
|
+
|
5
|
+
if __FILE__ == $0
|
6
|
+
if (ARGV.size == 2)
|
7
|
+
player1 = case ARGV[0].downcase
|
8
|
+
when "smart" then Tictactoe::SmartPlayer
|
9
|
+
when "minimax" then Tictactoe::MinimaxPlayer
|
10
|
+
when "dumb" then Tictactoe::DumbPlayer
|
11
|
+
when "human" then Tictactoe::HumanPlayer
|
12
|
+
else Tictactoe::HumanPlayer
|
13
|
+
end
|
14
|
+
|
15
|
+
player2 = case ARGV[1].downcase
|
16
|
+
when "smart" then Tictactoe::SmartPlayer
|
17
|
+
when "minimax" then Tictactoe::MinimaxPlayer
|
18
|
+
when "dumb" then Tictactoe::DumbPlayer
|
19
|
+
when "human" then Tictactoe::HumanPlayer
|
20
|
+
else Tictactoe::HumanPlayer
|
21
|
+
end
|
22
|
+
|
23
|
+
game = Tictactoe::Game.new(player1, player2, false)
|
24
|
+
game.play
|
25
|
+
else
|
26
|
+
puts "Usage: ruby -Ilib bin/tictactoe_game_players.rb player_x player_o"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tictactoe/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "game-tictactoe-alu3299"
|
8
|
+
gem.version = Tictactoe::VERSION
|
9
|
+
gem.authors = ["mdbgalvan"]
|
10
|
+
gem.email = ["magomenlopark@gmail.com"]
|
11
|
+
gem.description = %q{Juego del Tres en Rayas con dos jugadores o varios tipos virtuales. }
|
12
|
+
gem.summary = %q{Existen varios tipos de dificultad de jugadores virtuales.}
|
13
|
+
gem.homepage = "https://github.com/mdbGalvan/LPP_Lab9"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_development_dependency 'guard-rspec'
|
23
|
+
gem.add_development_dependency 'rb-readline'
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# File : game-tictactoe-alu3299.rb
|
2
|
+
|
3
|
+
require "tictactoe/version"
|
4
|
+
require "tictactoe/tictactoe"
|
5
|
+
require "tictactoe/humanplayer"
|
6
|
+
require "tictactoe/smartplayer"
|
7
|
+
require "tictactoe/dumbplayer"
|
8
|
+
require "tictactoe/minimaxplayer"
|
9
|
+
|
10
|
+
module Tictactoe
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# File : humanplayer.rb
|
2
|
+
|
3
|
+
require "tictactoe/player"
|
4
|
+
|
5
|
+
module Tictactoe
|
6
|
+
|
7
|
+
class HumanPlayer < Player
|
8
|
+
def move( board )
|
9
|
+
print board
|
10
|
+
|
11
|
+
moves = board.moves
|
12
|
+
print "Your move? (format: b3) "
|
13
|
+
move = $stdin.gets
|
14
|
+
until moves.include?(move.chomp.downcase)
|
15
|
+
print "Invalid move. Try again. "
|
16
|
+
move = $stdin.gets
|
17
|
+
end
|
18
|
+
move.chomp
|
19
|
+
end
|
20
|
+
|
21
|
+
def finish( final_board )
|
22
|
+
print final_board
|
23
|
+
|
24
|
+
if final_board.won? == @mark
|
25
|
+
print "Congratulations, you win.\n\n"
|
26
|
+
elsif final_board.won? == " "
|
27
|
+
print "Tie game.\n\n"
|
28
|
+
else
|
29
|
+
print "You lost tic-tac-toe?!\n\n"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# File : minimaxplayer.rb
|
2
|
+
|
3
|
+
require "tictactoe/player"
|
4
|
+
|
5
|
+
module Tictactoe
|
6
|
+
|
7
|
+
class MinimaxPlayer < Player
|
8
|
+
def move( board )
|
9
|
+
# Obtains the available movements
|
10
|
+
moves = board.moves
|
11
|
+
|
12
|
+
# For each available movement
|
13
|
+
bestValue = -2
|
14
|
+
bestMove = ""
|
15
|
+
moves.each do |mov|
|
16
|
+
newsquares = board.squares.dup
|
17
|
+
newboard = Board.new(newsquares)
|
18
|
+
newboard[mov] = self.mark
|
19
|
+
value = search_best_move(newboard, opponent_mark, 1)
|
20
|
+
if (value > bestValue)
|
21
|
+
bestValue = value
|
22
|
+
bestMove = mov
|
23
|
+
end
|
24
|
+
end
|
25
|
+
bestMove
|
26
|
+
end
|
27
|
+
|
28
|
+
def search_best_move(board, mark, level)
|
29
|
+
# Checks if there is a winner
|
30
|
+
return 1 if (board.won? == self.mark)
|
31
|
+
return 0 if (board.won? == " ")
|
32
|
+
return -1 if (board.won? == opponent_mark)
|
33
|
+
|
34
|
+
# Gets the available movements
|
35
|
+
moves = board.moves
|
36
|
+
|
37
|
+
# Min level
|
38
|
+
if ((level % 2 == 1) && (!board.won?))
|
39
|
+
bestValue = 2
|
40
|
+
moves.each do |mov|
|
41
|
+
newsquares = board.squares.dup
|
42
|
+
newboard = Board.new(newsquares)
|
43
|
+
newboard[mov] = mark
|
44
|
+
value = search_best_move(newboard, self.mark, level + 1)
|
45
|
+
if (value < bestValue)
|
46
|
+
bestValue = value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
# Max level
|
50
|
+
elsif ((level % 2 == 0) && (!board.won?))
|
51
|
+
bestValue = -2
|
52
|
+
moves.each do |mov|
|
53
|
+
newsquares = board.squares.dup
|
54
|
+
newboard = Board.new(newsquares)
|
55
|
+
newboard[mov] = mark
|
56
|
+
value = search_best_move(newboard, opponent_mark, level + 1)
|
57
|
+
if (value > bestValue)
|
58
|
+
bestValue = value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
bestValue
|
63
|
+
end
|
64
|
+
|
65
|
+
def opponent_mark
|
66
|
+
if (self.mark == "X")
|
67
|
+
return "O"
|
68
|
+
else
|
69
|
+
return "X"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# File : player.rb
|
2
|
+
|
3
|
+
module Tictactoe
|
4
|
+
class Player
|
5
|
+
def initialize( mark )
|
6
|
+
@mark = mark # "X" or "O" or " "
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :mark
|
10
|
+
|
11
|
+
def move( board )
|
12
|
+
raise NotImplementedError, "Player subclasses must define move()."
|
13
|
+
end
|
14
|
+
|
15
|
+
def finish( final_board )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# File : smartplayer.rb
|
2
|
+
|
3
|
+
require "tictactoe/player"
|
4
|
+
|
5
|
+
module Tictactoe
|
6
|
+
|
7
|
+
class SmartPlayer < Player
|
8
|
+
|
9
|
+
def move( board )
|
10
|
+
moves = board.moves
|
11
|
+
|
12
|
+
# If I have a win, take it. If he is threatening to win, stop it.
|
13
|
+
board.each_row do |row|
|
14
|
+
if row.blanks == 1 and (row.xs == 2 or row.os == 2)
|
15
|
+
(0..2).each do |e|
|
16
|
+
return row.to_board_name(e) if row[e] == " "
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Take the center if open.
|
22
|
+
return "b2" if moves.include? "b2"
|
23
|
+
|
24
|
+
# Defend opposite corners.
|
25
|
+
if board[0] != @mark and board[0] != " " and board[8] == " "
|
26
|
+
return "c3"
|
27
|
+
elsif board[8] != @mark and board[8] != " " and board[0] == " "
|
28
|
+
return "a1"
|
29
|
+
elsif board[2] != @mark and board[2] != " " and board[6] == " "
|
30
|
+
return "c1"
|
31
|
+
elsif board[6] != @mark and board[6] != " " and board[2] == " "
|
32
|
+
return "a3"
|
33
|
+
end
|
34
|
+
|
35
|
+
# Defend against the special case XOX on a diagonal.
|
36
|
+
if board.xs == 2 and board.os == 1 and board[4] == "O" and
|
37
|
+
(board[0] == "X" and board[8] == "X") or
|
38
|
+
(board[2] == "X" and board[6] == "X")
|
39
|
+
return %w{a2 b1 b3 c2}[rand(4)]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Or make a random move.
|
43
|
+
moves[rand(moves.size)]
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# File : tictactoe.rb
|
2
|
+
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
#---
|
5
|
+
# Visit http://www.pragmaticprogrammer.com/titles/fr_quiz for more book information.
|
6
|
+
#---
|
7
|
+
|
8
|
+
module Tictactoe
|
9
|
+
module SquaresContainer
|
10
|
+
def []( index ) @squares[index] end
|
11
|
+
|
12
|
+
def blanks() @squares.find_all { |s| s == " " }.size end
|
13
|
+
def os() @squares.find_all { |s| s == "O" }.size end
|
14
|
+
def xs() @squares.find_all { |s| s == "X" }.size end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Board
|
18
|
+
class Row
|
19
|
+
def initialize( squares, names )
|
20
|
+
@squares = squares
|
21
|
+
@names = names
|
22
|
+
end
|
23
|
+
|
24
|
+
include SquaresContainer
|
25
|
+
|
26
|
+
def to_board_name( index )
|
27
|
+
Board.index_to_name(@names[index])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
MOVES = %w{a1 a2 a3 b1 b2 b3 c1 c2 c3}
|
32
|
+
# Define constant INDICES
|
33
|
+
INDICES = Hash.new { |h, k| h[k] = MOVES.find_index(k) }
|
34
|
+
|
35
|
+
def self.name_to_index( name )# Receives "b2" and returns 4
|
36
|
+
INDICES[name]
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.index_to_name( index ) # Receives the index, like 4 and returns "b2"
|
40
|
+
MOVES[index]
|
41
|
+
end
|
42
|
+
|
43
|
+
def initialize( squares )
|
44
|
+
@squares = squares # An array of Strings: [ " ", " ", " ", " ", "X", " ", " ", " ", "O"]
|
45
|
+
end
|
46
|
+
|
47
|
+
include SquaresContainer
|
48
|
+
|
49
|
+
def []( *indices )
|
50
|
+
if indices.size == 2 # board[1,2] is @squares[7]
|
51
|
+
super indices[0] + indices[1] * 3 # calls SquaresContainer [] method
|
52
|
+
elsif indices[0].is_a? Fixnum # board[7]
|
53
|
+
super indices[0]
|
54
|
+
else # board["b2"]
|
55
|
+
super Board.name_to_index(indices[0].to_s)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def []=(indice, value) # board["b2"] = "X"
|
60
|
+
m = Board.name_to_index(indice)
|
61
|
+
@squares[m] = value
|
62
|
+
end
|
63
|
+
|
64
|
+
HORIZONTALS = [ [0, 1, 2], [3, 4, 5], [6, 7, 8] ]
|
65
|
+
COLUMNS = [ [0, 3, 6], [1, 4, 7], [2, 5, 8] ]
|
66
|
+
DIAGONALS = [ [0, 4, 8], [2, 4, 6] ]
|
67
|
+
ROWS = HORIZONTALS + COLUMNS + DIAGONALS
|
68
|
+
|
69
|
+
def each_row
|
70
|
+
ROWS.each do |e|
|
71
|
+
yield Row.new(@squares.values_at(*e), e)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def moves
|
76
|
+
moves = [ ]
|
77
|
+
@squares.each_with_index do |s, i|
|
78
|
+
moves << Board.index_to_name(i) if s == " "
|
79
|
+
end
|
80
|
+
moves # returns the set of feasible moves [ "b3", "c2", ... ]
|
81
|
+
end
|
82
|
+
|
83
|
+
def won?
|
84
|
+
each_row do |row|
|
85
|
+
return "X" if row.xs == 3 # "X" wins
|
86
|
+
return "O" if row.os == 3 # "O" wins
|
87
|
+
end
|
88
|
+
return " " if blanks == 0 # tie
|
89
|
+
false
|
90
|
+
end
|
91
|
+
|
92
|
+
BOARD =<<EOS
|
93
|
+
|
94
|
+
+---+---+---+
|
95
|
+
a | 0 | 1 | 2 |
|
96
|
+
+---+---+---+
|
97
|
+
b | 3 | 4 | 5 |
|
98
|
+
+---+---+---+
|
99
|
+
c | 6 | 7 | 8 |
|
100
|
+
+---+---+---+
|
101
|
+
1 2 3
|
102
|
+
|
103
|
+
EOS
|
104
|
+
def to_s
|
105
|
+
BOARD.gsub(/(\d)(?= \|)/) { |i| @squares[i.to_i] }
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
module Tictactoe
|
112
|
+
class Game
|
113
|
+
def initialize( player1, player2, random = true )
|
114
|
+
if random and rand(2) == 1
|
115
|
+
@x_player = player2.new("X")
|
116
|
+
@o_player = player1.new("O")
|
117
|
+
else
|
118
|
+
@x_player = player1.new("X")
|
119
|
+
@o_player = player2.new("O")
|
120
|
+
end
|
121
|
+
|
122
|
+
@board = Board.new([" "] * 9)
|
123
|
+
end
|
124
|
+
|
125
|
+
attr_reader :x_player, :o_player
|
126
|
+
|
127
|
+
def play
|
128
|
+
until @board.won?
|
129
|
+
@board[@x_player.move(@board)] = @x_player.mark
|
130
|
+
break if @board.won?
|
131
|
+
|
132
|
+
@board[@o_player.move(@board)] = @o_player.mark
|
133
|
+
end
|
134
|
+
|
135
|
+
@o_player.finish @board
|
136
|
+
@x_player.finish @board
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# File : dumbplayer_spec.rb
|
2
|
+
|
3
|
+
require "game-tictactoe-alu3299"
|
4
|
+
|
5
|
+
describe Tictactoe::DumbPlayer do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@dp = Tictactoe::DumbPlayer.new("X")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "Debe existir un metodo move" do
|
12
|
+
@dp.respond_to?("move").should == true
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# File : humanplayer_spec.rb
|
2
|
+
|
3
|
+
require "game-tictactoe-alu3299"
|
4
|
+
|
5
|
+
describe Tictactoe::HumanPlayer do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@hp = Tictactoe::HumanPlayer.new("X")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "Debe existir un metodo move" do
|
12
|
+
@hp.respond_to?("move").should == true
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# File : minimaxplayer_spec.rb
|
2
|
+
|
3
|
+
require "game-tictactoe-alu3299"
|
4
|
+
|
5
|
+
describe Tictactoe::MinimaxPlayer do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@mp = Tictactoe::MinimaxPlayer.new("X")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "Debe existir un metodo move" do
|
12
|
+
@mp.respond_to?("move").should == true
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# File : smartplayer_spec.rb
|
2
|
+
|
3
|
+
require "game-tictactoe-alu3299"
|
4
|
+
|
5
|
+
describe Tictactoe::SmartPlayer do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@sp = Tictactoe::SmartPlayer.new("X")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "Debe existir un metodo move" do
|
12
|
+
@sp.respond_to?("move").should == true
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# File : tc_dumbplayer.rb
|
2
|
+
|
3
|
+
require "game-tictactoe-alu3299"
|
4
|
+
require "test/unit"
|
5
|
+
|
6
|
+
class TestDumbPlayer < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@dp = Tictactoe::DumbPlayer.new("X")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_implements_move
|
13
|
+
assert_equal true, @dp.respond_to?("move")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# File : tc_humanplayer.rb
|
2
|
+
|
3
|
+
require "game-tictactoe-alu3299"
|
4
|
+
require "test/unit"
|
5
|
+
|
6
|
+
class TestHumanPlayer < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@hp = Tictactoe::HumanPlayer.new("X")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_implements_move
|
13
|
+
assert_equal true, @hp.respond_to?("move")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# File : tc_minimaxplayer.rb
|
2
|
+
|
3
|
+
require "game-tictactoe-alu3299"
|
4
|
+
require "test/unit"
|
5
|
+
|
6
|
+
class TestMinimaxPlayer < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@mp = Tictactoe::MinimaxPlayer.new("X")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_implements_move
|
13
|
+
assert_equal true, @mp.respond_to?("move")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# File : tc_smartplayer.rb
|
2
|
+
|
3
|
+
require "game-tictactoe-alu3299"
|
4
|
+
require "test/unit"
|
5
|
+
|
6
|
+
class TestSmartPlayer < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@sp = Tictactoe::SmartPlayer.new("X")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_implements_move
|
13
|
+
assert_equal true, @sp.respond_to?("move")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: game-tictactoe-alu3299
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- mdbgalvan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: guard-rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rb-readline
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: ! 'Juego del Tres en Rayas con dos jugadores o varios tipos virtuales. '
|
79
|
+
email:
|
80
|
+
- magomenlopark@gmail.com
|
81
|
+
executables:
|
82
|
+
- game_tictactoe.rb
|
83
|
+
- game_tictactoe_players.rb
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- Gemfile
|
89
|
+
- Guardfile
|
90
|
+
- LICENSE.txt
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- bin/game_tictactoe.rb
|
94
|
+
- bin/game_tictactoe_players.rb
|
95
|
+
- game-tictactoe-alu3299.gemspec
|
96
|
+
- lib/game-tictactoe-alu3299.rb
|
97
|
+
- lib/tictactoe/dumbplayer.rb
|
98
|
+
- lib/tictactoe/humanplayer.rb
|
99
|
+
- lib/tictactoe/minimaxplayer.rb
|
100
|
+
- lib/tictactoe/player.rb
|
101
|
+
- lib/tictactoe/smartplayer.rb
|
102
|
+
- lib/tictactoe/tictactoe.rb
|
103
|
+
- lib/tictactoe/version.rb
|
104
|
+
- spec/dumbplayer_spec.rb
|
105
|
+
- spec/humanplayer_spec.rb
|
106
|
+
- spec/minimaxplayer_spec.rb
|
107
|
+
- spec/smartplayer_spec.rb
|
108
|
+
- test/tc_dumbplayer.rb
|
109
|
+
- test/tc_humanplayer.rb
|
110
|
+
- test/tc_minimaxplayer.rb
|
111
|
+
- test/tc_smartplayer.rb
|
112
|
+
homepage: https://github.com/mdbGalvan/LPP_Lab9
|
113
|
+
licenses: []
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 1.8.24
|
133
|
+
signing_key:
|
134
|
+
specification_version: 3
|
135
|
+
summary: Existen varios tipos de dificultad de jugadores virtuales.
|
136
|
+
test_files:
|
137
|
+
- spec/dumbplayer_spec.rb
|
138
|
+
- spec/humanplayer_spec.rb
|
139
|
+
- spec/minimaxplayer_spec.rb
|
140
|
+
- spec/smartplayer_spec.rb
|
141
|
+
- test/tc_dumbplayer.rb
|
142
|
+
- test/tc_humanplayer.rb
|
143
|
+
- test/tc_minimaxplayer.rb
|
144
|
+
- test/tc_smartplayer.rb
|