Tictactoe-alu4116 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Guardfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/README.md~ +55 -0
- data/Rakefile +54 -0
- data/Rakefile~ +54 -0
- data/Tictactoe-alu4116.gemspec +20 -0
- data/Tictactoe-alu4116.gemspec~ +20 -0
- data/bin/game.rb +13 -0
- data/bin/game.rb~ +13 -0
- data/bin/game_competicion.rb +15 -0
- data/bin/game_competicion.rb~ +15 -0
- data/lib/Tictactoe-alu4116.rb +57 -0
- data/lib/Tictactoe-alu4116.rb~ +57 -0
- data/lib/Tictactoe-alu4116/board.rb +96 -0
- data/lib/Tictactoe-alu4116/board.rb~ +96 -0
- data/lib/Tictactoe-alu4116/dumb_player.rb +15 -0
- data/lib/Tictactoe-alu4116/dumb_player.rb~ +15 -0
- data/lib/Tictactoe-alu4116/esquinas_player.rb +40 -0
- data/lib/Tictactoe-alu4116/esquinas_player.rb~ +40 -0
- data/lib/Tictactoe-alu4116/human_player.rb +46 -0
- data/lib/Tictactoe-alu4116/human_player.rb~ +46 -0
- data/lib/Tictactoe-alu4116/player.rb +21 -0
- data/lib/Tictactoe-alu4116/player.rb~ +18 -0
- data/lib/Tictactoe-alu4116/smart_player.rb +48 -0
- data/lib/Tictactoe-alu4116/smart_player.rb~ +48 -0
- data/lib/Tictactoe-alu4116/squares_container.rb +9 -0
- data/lib/Tictactoe-alu4116/version.rb +5 -0
- data/spec/tictactoe_spec.rb +134 -0
- data/spec/tictactoe_spec.rb~ +134 -0
- data/test/tc_tictactoe.rb +135 -0
- metadata +100 -0
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ayo91
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Tictactoe::Game
|
2
|
+
Descripción de la práctica:
|
3
|
+
Primera parte:
|
4
|
+
Considere el desarrollo de una aplicación para jugar al tres en raya.
|
5
|
+
El objetivo de esta práctica es la creación de una Gema en Ruby para el juego de tres en raya. Para ello se ha de utilizar la herramienta Bundler (http://gembundler.com/)
|
6
|
+
1.- Utilizar bundle para crear la estructura estandar de una gema. Véanse railcast: gems with bundler y el blog polishing rubies bundle gem tictactoe
|
7
|
+
2.- Partiendo de la implementacion del juego que está disponible en github separar a los jugadores en diferentes ficheros y utilizarlos como plugins.
|
8
|
+
3.- Escribir un conjunto de pruebas unitarias (Unit Testing) test/tc_tictactoe.rb
|
9
|
+
4.- Escribir un fichero de espectativas de comportamiento (BDD) spec/tictactoe_spec.rb
|
10
|
+
5.- Realizar un seguimiento continuo de las pruebas (Continuous Testing) guard
|
11
|
+
6.- Comprobar el correcto funcionamiento en distintas plataformas (Continuous Integration) travis
|
12
|
+
7.- Indique la URL del repositorio github o bitbucket que ha desarrollado.
|
13
|
+
|
14
|
+
Segunda parte:
|
15
|
+
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/)
|
16
|
+
1.- Desarrollar un método para hacer que dos jugadores arbitrarios compitan
|
17
|
+
2.- Desarrollar un jugador minimax
|
18
|
+
3.- Construir la gema: gem build
|
19
|
+
4.- Considerar su publicacion: gem push
|
20
|
+
5.- Indique la URL del repositorio github o bitbucket que ha desarrollado.
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
gem 'tictactoe-game'
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ ruby -Ilib bin/game.rb
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install tictactoe-game
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
TODO: Dispone de un rakefile con las tareas siguientes:
|
41
|
+
-bin1: ejecuta una partida del juego con un adversario inteligente
|
42
|
+
-bin2: ejecuta una partida del juego con un adversario idiota
|
43
|
+
-bin3: ejecuta una partida del juego con un adversario esquinas
|
44
|
+
-comp: competicion entre agentes arbitrarios
|
45
|
+
-spec: ejecuta las espectativas de comportamiento
|
46
|
+
-test: ejecuta el conjunto de pruebas unitarias
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/README.md~
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Tictactoe::Game
|
2
|
+
Descripción de la práctica:
|
3
|
+
Primera parte:
|
4
|
+
Considere el desarrollo de una aplicación para jugar al tres en raya.
|
5
|
+
El objetivo de esta práctica es la creación de una Gema en Ruby para el juego de tres en raya. Para ello se ha de utilizar la herramienta Bundler (http://gembundler.com/)
|
6
|
+
1.- Utilizar bundle para crear la estructura estandar de una gema. Véanse railcast: gems with bundler y el blog polishing rubies bundle gem tictactoe
|
7
|
+
2.- Partiendo de la implementacion del juego que está disponible en github separar a los jugadores en diferentes ficheros y utilizarlos como plugins.
|
8
|
+
3.- Escribir un conjunto de pruebas unitarias (Unit Testing) test/tc_tictactoe.rb
|
9
|
+
4.- Escribir un fichero de espectativas de comportamiento (BDD) spec/tictactoe_spec.rb
|
10
|
+
5.- Realizar un seguimiento continuo de las pruebas (Continuous Testing) guard
|
11
|
+
6.- Comprobar el correcto funcionamiento en distintas plataformas (Continuous Integration) travis
|
12
|
+
7.- Indique la URL del repositorio github o bitbucket que ha desarrollado.
|
13
|
+
|
14
|
+
Segunda parte:
|
15
|
+
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/)
|
16
|
+
1.- Desarrollar un método para hacer que dos jugadores arbitrarios compitan
|
17
|
+
2.- Desarrollar un jugador minimax
|
18
|
+
3.- Construir la gema: gem build
|
19
|
+
4.- Considerar su publicacion: gem push
|
20
|
+
5.- Indique la URL del repositorio github o bitbucket que ha desarrollado.
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
gem 'tictactoe-game'
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ ruby -Ilib bin/game.rb
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install tictactoe-game
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
TODO: Dispone de un rakefile con las tareas siguientes:
|
41
|
+
-bin1: ejecuta una partida del juego con un adversario inteligente
|
42
|
+
-bin2: ejecuta una partida del juego con un adversario idiota
|
43
|
+
-bin3: ejecuta una partida del juego con un adversario minimax
|
44
|
+
-comp: competicion entre agentes arbitrarios
|
45
|
+
-spec: ejecuta las espectativas de comportamiento
|
46
|
+
-test: ejecuta el conjunto de pruebas unitarias
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
require "bundler/gem_tasks" #tarea de construccion
|
5
|
+
require "rake/clean" #tarea de borrado
|
6
|
+
CLOBBER.include('pkg/*.gem' )
|
7
|
+
|
8
|
+
|
9
|
+
#para no tener que poner -Ilib
|
10
|
+
$:.unshift File.dirname(__FILE__) + 'lib'
|
11
|
+
|
12
|
+
#-------------------------------------------------------------------------------
|
13
|
+
task :default => :spec
|
14
|
+
|
15
|
+
#-------------------------------------------------------------------------------
|
16
|
+
desc "Ejecutar tests"
|
17
|
+
task :spec do
|
18
|
+
sh "rspec spec/tictactoe_spec.rb --format documentation"
|
19
|
+
end
|
20
|
+
|
21
|
+
#-------------------------------------------------------------------------------
|
22
|
+
desc "Ejecutar una partida del juego contra adversario inteligente"
|
23
|
+
task :bin1 do
|
24
|
+
sh "ruby -Ilib bin/game.rb"
|
25
|
+
end
|
26
|
+
|
27
|
+
#-------------------------------------------------------------------------------
|
28
|
+
desc "Ejecutar una partida del juego contra adversario idiota"
|
29
|
+
task :bin2 do
|
30
|
+
sh "ruby -Ilib bin/game.rb -d"
|
31
|
+
end
|
32
|
+
|
33
|
+
#-------------------------------------------------------------------------------
|
34
|
+
desc "Ejecutar una partida del juego contra adversario esquinas: Siempre prefiere colocar ficha en las esquinas"
|
35
|
+
task :bin3 do
|
36
|
+
sh "ruby -Ilib bin/game.rb -m"
|
37
|
+
end
|
38
|
+
|
39
|
+
#-------------------------------------------------------------------------------
|
40
|
+
desc "Competicion arbitraria entre dos jugadores: Tres tipos de jugadores: EsquinasPlayer, SmartPlayer y DumbPlayer"
|
41
|
+
task :comp do
|
42
|
+
sh "ruby -Ilib bin/game_competicion.rb"
|
43
|
+
end
|
44
|
+
|
45
|
+
#-------------------------------------------------------------------------------
|
46
|
+
desc "Ejecutar test con formato html"
|
47
|
+
task :thtml do
|
48
|
+
sh "rspec spec/tictactoe_spec.rb --format html > resultados.html"
|
49
|
+
end
|
50
|
+
|
51
|
+
#-------------------------------------------------------------------------------
|
52
|
+
task :test do
|
53
|
+
sh "ruby -w -Ilib test/tc_tictactoe.rb"
|
54
|
+
end
|
data/Rakefile~
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
require "bundler/gem_tasks" #tarea de construccion
|
5
|
+
require "rake/clean" #tarea de borrado
|
6
|
+
CLOBBER.include('pkg/*.gem' )
|
7
|
+
|
8
|
+
|
9
|
+
#para no tener que poner -Ilib
|
10
|
+
$:.unshift File.dirname(__FILE__) + 'lib'
|
11
|
+
|
12
|
+
#-------------------------------------------------------------------------------
|
13
|
+
task :default => :spec
|
14
|
+
|
15
|
+
#-------------------------------------------------------------------------------
|
16
|
+
desc "Ejecutar tests"
|
17
|
+
task :spec do
|
18
|
+
sh "rspec spec/tictactoe_spec.rb --format documentation"
|
19
|
+
end
|
20
|
+
|
21
|
+
#-------------------------------------------------------------------------------
|
22
|
+
desc "Ejecutar una partida del juego contra adversario inteligente"
|
23
|
+
task :bin1 do
|
24
|
+
sh "ruby -Ilib bin/game.rb"
|
25
|
+
end
|
26
|
+
|
27
|
+
#-------------------------------------------------------------------------------
|
28
|
+
desc "Ejecutar una partida del juego contra adversario idiota"
|
29
|
+
task :bin2 do
|
30
|
+
sh "ruby -Ilib bin/game.rb -d"
|
31
|
+
end
|
32
|
+
|
33
|
+
#-------------------------------------------------------------------------------
|
34
|
+
desc "Ejecutar una partida del juego contra adversario esquinas: Siempre prefiere colocar ficha en las esquinas"
|
35
|
+
task :bin3 do
|
36
|
+
sh "ruby -Ilib bin/game.rb -m"
|
37
|
+
end
|
38
|
+
|
39
|
+
#-------------------------------------------------------------------------------
|
40
|
+
desc "Competicion arbitraria entre dos jugadores"
|
41
|
+
task :comp do
|
42
|
+
sh "ruby -Ilib bin/game_competicion.rb"
|
43
|
+
end
|
44
|
+
|
45
|
+
#-------------------------------------------------------------------------------
|
46
|
+
desc "Ejecutar test con formato html"
|
47
|
+
task :thtml do
|
48
|
+
sh "rspec spec/tictactoe_spec.rb --format html > resultados.html"
|
49
|
+
end
|
50
|
+
|
51
|
+
#-------------------------------------------------------------------------------
|
52
|
+
task :test do
|
53
|
+
sh "ruby -w -Ilib test/tc_tictactoe.rb"
|
54
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "Tictactoe-alu4116/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "Tictactoe-alu4116"
|
7
|
+
s.version = Tictactoe::Alu4116::VERSION
|
8
|
+
s.authors = ["Ayo91"]
|
9
|
+
s.email = ["ayoze.peraza@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{"-----"}
|
12
|
+
s.description = %q{"Juego del tres en raya"}
|
13
|
+
|
14
|
+
s.rubyforge_project = "Tictactoe-alu4116"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "Tictactoe-alu4116/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "Tictactoe-alu4116"
|
7
|
+
s.version = Tictactoe::Alu4116::VERSION
|
8
|
+
s.authors = ["Ayo91"]
|
9
|
+
s.email = ["ayoze.peraza@gmail.com"]
|
10
|
+
s.homepage = " "
|
11
|
+
s.summary = %q{"-----"}
|
12
|
+
s.description = %q{"Juego del tres en raya"}
|
13
|
+
|
14
|
+
s.rubyforge_project = "Tictactoe-alu4116"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
data/bin/game.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'Tictactoe-alu4116'
|
2
|
+
|
3
|
+
if ARGV.size > 0 and ARGV[0] == "-d"
|
4
|
+
game = Tictactoe::Game.new Tictactoe::HumanPlayer,
|
5
|
+
Tictactoe::DumbPlayer
|
6
|
+
elsif ARGV.size > 0 and ARGV[0] == "-m"
|
7
|
+
game = Tictactoe::Game.new Tictactoe::HumanPlayer,
|
8
|
+
Tictactoe::EsquinasPlayer
|
9
|
+
else
|
10
|
+
game = Tictactoe::Game.new Tictactoe::HumanPlayer,
|
11
|
+
Tictactoe::SmartPlayer
|
12
|
+
end
|
13
|
+
game.play
|
data/bin/game.rb~
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'Tictactoe-alu4116'
|
2
|
+
|
3
|
+
if ARGV.size > 0 and ARGV[0] == "-d"
|
4
|
+
game = Tictactoe::Game.new Tictactoe::HumanPlayer,
|
5
|
+
Tictactoe::DumbPlayer
|
6
|
+
elsif ARGV.size > 0 and ARGV[0] == "-m"
|
7
|
+
game = Tictactoe::Game.new Tictactoe::HumanPlayer,
|
8
|
+
Tictactoe::EsquinasPlayer
|
9
|
+
else
|
10
|
+
game = Tictactoe::Game.new Tictactoe::HumanPlayer,
|
11
|
+
Tictactoe::SmartPlayer
|
12
|
+
end
|
13
|
+
game.play
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'Tictactoe-alu4116'
|
2
|
+
|
3
|
+
valor = rand(3)
|
4
|
+
if valor == 0
|
5
|
+
game = Tictactoe::Game.new Tictactoe::DumbPlayer,Tictactoe::SmartPlayer
|
6
|
+
|
7
|
+
elsif valor == 1
|
8
|
+
game = Tictactoe::Game.new Tictactoe::DumbPlayer,Tictactoe::EsquinasPlayer
|
9
|
+
|
10
|
+
else
|
11
|
+
game = Tictactoe::Game.new Tictactoe::EsquinasPlayer,Tictactoe::SmartPlayer
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
game.competicion
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'Tictactoe-alu4116'
|
2
|
+
|
3
|
+
valor = rand(3)
|
4
|
+
if valor == 0
|
5
|
+
game = Tictactoe::Game.new Tictactoe::DumbPlayer,Tictactoe::SmartPlayer
|
6
|
+
|
7
|
+
elsif valor == 1
|
8
|
+
game = Tictactoe::Game.new Tictactoe::DumbPlayer,Tictactoe::EsquinasPlayer
|
9
|
+
|
10
|
+
else
|
11
|
+
game = Tictactoe::Game.new Tictactoe::EsquinasPlayer,Tictactoe::SmartPlayer
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
game.competicion
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "Tictactoe-alu4116/version"
|
2
|
+
require "Tictactoe-alu4116/squares_container"
|
3
|
+
require "Tictactoe-alu4116/board"
|
4
|
+
require "Tictactoe-alu4116/player"
|
5
|
+
require "Tictactoe-alu4116/human_player"
|
6
|
+
require "Tictactoe-alu4116/dumb_player"
|
7
|
+
require "Tictactoe-alu4116/esquinas_player"
|
8
|
+
require "Tictactoe-alu4116/smart_player"
|
9
|
+
|
10
|
+
|
11
|
+
module Tictactoe
|
12
|
+
class Game
|
13
|
+
def initialize( player1, player2, random = true )
|
14
|
+
if random and rand(2) == 1
|
15
|
+
@x_player = player2.new("X")
|
16
|
+
@o_player = player1.new("O")
|
17
|
+
else
|
18
|
+
@x_player = player1.new("X")
|
19
|
+
@o_player = player2.new("O")
|
20
|
+
end
|
21
|
+
|
22
|
+
@board = Board.new([" "] * 9)
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :x_player, :o_player
|
26
|
+
|
27
|
+
def play
|
28
|
+
until @board.won?
|
29
|
+
@board[@x_player.move(@board)] = @x_player.mark
|
30
|
+
break if @board.won?
|
31
|
+
|
32
|
+
@board[@o_player.move(@board)] = @o_player.mark
|
33
|
+
end
|
34
|
+
|
35
|
+
@o_player.finish @board
|
36
|
+
@x_player.finish @board
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def competicion
|
41
|
+
puts " "
|
42
|
+
puts "COMPETICION"
|
43
|
+
puts "#{@o_player.start} \n#{@x_player.start}"
|
44
|
+
puts " "
|
45
|
+
|
46
|
+
until @board.won?
|
47
|
+
print @board
|
48
|
+
@board[@x_player.move(@board)] = @x_player.mark
|
49
|
+
break if @board.won?
|
50
|
+
|
51
|
+
@board[@o_player.move(@board)] = @o_player.mark
|
52
|
+
end
|
53
|
+
|
54
|
+
print @board
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "Tictactoe-alu4116/version"
|
2
|
+
require "Tictactoe-alu4116/squares_container"
|
3
|
+
require "Tictactoe-alu4116/board"
|
4
|
+
require "Tictactoe-alu4116/player"
|
5
|
+
require "Tictactoe-alu4116/human_player"
|
6
|
+
require "Tictactoe-alu4116/dumb_player"
|
7
|
+
require "Tictactoe-alu4116/esquinas_player"
|
8
|
+
require "Tictactoe-alu4116/smart_player"
|
9
|
+
|
10
|
+
|
11
|
+
module Tictactoe
|
12
|
+
class Game
|
13
|
+
def initialize( player1, player2, random = true )
|
14
|
+
if random and rand(2) == 1
|
15
|
+
@x_player = player2.new("X")
|
16
|
+
@o_player = player1.new("O")
|
17
|
+
else
|
18
|
+
@x_player = player1.new("X")
|
19
|
+
@o_player = player2.new("O")
|
20
|
+
end
|
21
|
+
|
22
|
+
@board = Board.new([" "] * 9)
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :x_player, :o_player
|
26
|
+
|
27
|
+
def play
|
28
|
+
until @board.won?
|
29
|
+
@board[@x_player.move(@board)] = @x_player.mark
|
30
|
+
break if @board.won?
|
31
|
+
|
32
|
+
@board[@o_player.move(@board)] = @o_player.mark
|
33
|
+
end
|
34
|
+
|
35
|
+
@o_player.finish @board
|
36
|
+
@x_player.finish @board
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def competicion
|
41
|
+
puts " "
|
42
|
+
puts "COMPETICION"
|
43
|
+
puts "#{@o_player.start} \n#{@x_player.start}"
|
44
|
+
puts " "
|
45
|
+
|
46
|
+
until @board.won?
|
47
|
+
print @board
|
48
|
+
@board[@x_player.move(@board)] = @x_player.mark
|
49
|
+
break if @board.won?
|
50
|
+
|
51
|
+
@board[@o_player.move(@board)] = @o_player.mark
|
52
|
+
end
|
53
|
+
|
54
|
+
print @board
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|