rubykon 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0c6f51cb33c58227a82783ff663d546397ef750
4
- data.tar.gz: 2764e68e3b5a9ecc0ed8b1e62273201bf8748962
3
+ metadata.gz: 719c9cb87af8a842ef98569911f50788ab6c0943
4
+ data.tar.gz: 0a6e0f63e45886fbec9c4f993b88488d35fd0709
5
5
  SHA512:
6
- metadata.gz: 8d3d477881d123c94556c396885002ff3e01708f6f147c8aa1ceb7b625189de8d6f59202393d8f9806e75ef7743ccbd204c6f37e136b5dbe26b7f631eb5067f3
7
- data.tar.gz: e5b6acffc005f3e3ad2098cb7c3efc37b95253e8d58288a486d46f43b7c12dd047e80b528dd95ad47fd7d5ad4b510bcea5db48b6da333d1767dd9b810c2b4993
6
+ metadata.gz: 3adfcd1fafb3ecb4eec479e2e09cea8bbcee5158a9cafc16b0b09adafb654c778d1f5a20fff8899015635d78c0ede536b95e5601918534491baa410aedc0e499
7
+ data.tar.gz: 2045fb60ecba1096171bd54ad770d118aee5dacb2175ac10f53e3e11418e4627817d91bc70a846ebfc51cd83867c4c581008bb6836a3717b21aa0954f9f4ff31
@@ -1,4 +1,14 @@
1
- ## 0.3 (2015-11-12)
1
+ ## 0.3.1
2
+ Fixups to the CLI after the fast release.
3
+
4
+ ### Bugfixes
5
+ * fix wrong magic comment in gem executable
6
+ * do not allow invalid moves in the CLI
7
+ * implement `wdyt` command to ask rubykon what it is thinking
8
+ * make FakeIO return nil on print/puts as it should be
9
+ * Allow lower case move input (a19)
10
+
11
+ ## 0.3 (2015-11-17)
2
12
  Implement full bot together with Monte Carlo Tree Search, as well as a more coarse grained benchmarking tool to benchmark full MCTS runs. Also add a CLI. Mostly a feature release.
3
13
 
4
14
  ### Performance
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
- # Rubykon [![Build Status](https://secure.travis-ci.org/PragTob/rubykon.png?branch=master)](https://travis-ci.org/PragTob/rubykon)[![Code Climate](https://codeclimate.com/github/PragTob/Rubykon.png)](https://codeclimate.com/github/PragTob/Rubykon)[![Test Coverage](https://codeclimate.com/github/PragTob/Rubykon/badges/coverage.svg)](https://codeclimate.com/github/PragTob/Rubykon/coverage)
1
+ # Rubykon [![Gem Version](https://badge.fury.io/rb/rubykon.svg)](https://badge.fury.io/rb/rubykon)[![Build Status](https://secure.travis-ci.org/PragTob/rubykon.png?branch=master)](https://travis-ci.org/PragTob/rubykon)[![Code Climate](https://codeclimate.com/github/PragTob/Rubykon.png)](https://codeclimate.com/github/PragTob/Rubykon)[![Test Coverage](https://codeclimate.com/github/PragTob/Rubykon/badges/coverage.svg)](https://codeclimate.com/github/PragTob/Rubykon/coverage)
2
2
  A Go-Engine being built in Ruby.
3
3
 
4
4
  ### Status?
5
- A naive very slow implementation of random playouts. Next up making it faster... or implementing the mcts bits. We'll see. Don't use and judge yet, some pretty inefficient stuff in here :D
5
+ There is a CLI with which you can play, it does a full UCT MCTS. Still work to do on making move generation and scoring faster. Also there is no AMAF/RAVE implementation yet (which would make it a lot stronger) and it also does not use any expert knowledge right now. So still a lot to do, but it works.
6
+
7
+
8
+ ### Sub gems
9
+ Right now the `mcts` and `benchmark/avg` gem that I wrote for this are still embedded in here. They are bound to be broken out and released as separate gems to play with. If you want to use them now, just use rubykon and you can require `mcts` or `benchmark/avg` :)
6
10
 
7
11
  ### Why would you build a Go-Bot in Ruby?
8
12
  Cause it's fun.
@@ -1,4 +1,4 @@
1
- #!/usr/exe/env ruby
1
+ #!/usr/bin/env ruby
2
2
  require_relative '../lib/rubykon'
3
3
 
4
4
  cli = Rubykon::CLI.new
@@ -1,15 +1,19 @@
1
1
  module Rubykon
2
2
  class CLI
3
3
 
4
- EXIT = /exit/i
5
- CHAR_LABELS = GTPCoordinateConverter::X_CHARS
6
- X_LABEL_PADDING = ' '.freeze * 4
7
- Y_LABEL_WIDTH = 3
4
+ EXIT = /exit/i
5
+ CHAR_LABELS = GTPCoordinateConverter::X_CHARS
6
+ X_LABEL_PADDING = ' '.freeze * 4
7
+ Y_LABEL_WIDTH = 3
8
+ GTP_COORDINATE = /^[A-Z]\d\d?$/
9
+ MOVE_CONSIDERATIONS_COUNT = 10
8
10
 
9
11
  def initialize(output = $stdout, input = $stdin)
10
- @output = output
11
- @input = input
12
- @state = :init
12
+ @output = output
13
+ @input = input
14
+ @state = :init
15
+ @move_validator = MoveValidator.new
16
+ @root = nil
13
17
  end
14
18
 
15
19
  def start
@@ -18,7 +22,7 @@ module Rubykon
18
22
  @output.puts <<-PLAYOUTS
19
23
  Please enter the number of playouts you'd like rubykon to make!
20
24
  More playouts means rubykon is stronger, but also takes longer.
21
- For 9x9 10000 is an acceptable value, for 19x19 1000 already take a long time.
25
+ For 9x9 10000 is an acceptable value, for 19x19 1000 already take a long time (but still plays bad).
22
26
  PLAYOUTS
23
27
  playouts = get_digit_input
24
28
  init_game(size, playouts)
@@ -68,7 +72,7 @@ For 9x9 10000 is an acceptable value, for 19x19 1000 already take a long time.
68
72
  if bot_turn?
69
73
  bot_move
70
74
  else
71
- human_move
75
+ human_input
72
76
  end
73
77
  end
74
78
  end
@@ -96,19 +100,55 @@ For 9x9 10000 is an acceptable value, for 19x19 1000 already take a long time.
96
100
 
97
101
  def bot_move
98
102
  @output.puts 'Rubykon is thinking...'
99
- root = @mcts.start @game_state, @playouts
100
- move = root.best_move
101
- best_children = root.children.sort_by(&:win_percentage).reverse.take(10)
102
- @output.puts best_children.map {|child| "#{@gtp_converter.to(child.move.first)} => #{child.win_percentage}"}.join "\n"
103
+ @root = @mcts.start @game_state, @playouts
104
+ move = @root.best_move
103
105
  make_move(move)
104
106
  end
105
107
 
106
- def human_move
108
+ def human_input
109
+ input = ask_for_input.upcase
110
+ case input
111
+ when GTP_COORDINATE
112
+ human_move(input)
113
+ when 'WDYT'.freeze
114
+ print_move_considerations
115
+ else
116
+ invalid_input
117
+ end
118
+ end
119
+
120
+ def ask_for_input
107
121
  @output.puts "Make a move in the form XY, e.g. A19, D7 as the labels indicate!"
108
- coords = get_input
109
- identifier = @gtp_converter.from(coords)
110
- move = [identifier, :white]
111
- make_move(move)
122
+ @output.puts 'Or ask rubykon what it is thinking with "wdyt"'
123
+ get_input
124
+ end
125
+
126
+ def human_move(input)
127
+ move = move_from_input(input)
128
+ if @move_validator.valid?(*move, @game_state.game)
129
+ make_move(move)
130
+ else
131
+ retry_input
132
+ end
133
+ end
134
+
135
+ def retry_input
136
+ @output.puts 'That was an invalid move, please try again!'
137
+ human_input
138
+ end
139
+
140
+ def print_move_considerations
141
+ best_children = @root.children.sort_by(&:win_percentage).reverse
142
+ top_children = best_children.take(MOVE_CONSIDERATIONS_COUNT)
143
+ moves_to_win_percentage = top_children.map do |child|
144
+ "#{@gtp_converter.to(child.move.first)} => #{child.win_percentage * 100}%"
145
+ end.join "\n"
146
+ @output.puts moves_to_win_percentage
147
+ end
148
+
149
+ def move_from_input(input)
150
+ identifier = @gtp_converter.from(input)
151
+ [identifier, :white]
112
152
  end
113
153
 
114
154
  def make_move(move)
@@ -118,5 +158,9 @@ For 9x9 10000 is an acceptable value, for 19x19 1000 already take a long time.
118
158
  @output.puts "#{@game.next_turn_color}'s turn to move!'"
119
159
  end
120
160
 
161
+ def invalid_input
162
+ puts "Sorry, didn't catch that!"
163
+ end
164
+
121
165
  end
122
166
  end
@@ -1,3 +1,3 @@
1
1
  module Rubykon
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubykon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Pfeiffer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-16 00:00:00.000000000 Z
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An AI to play Go using Monte Carlo Tree Search. Currently includes the
14
14
  mcts gem and benchmark/avg. Works on all major ruby versions.