Class: Shuriken::Cmd
- Inherits:
-
Object
- Object
- Shuriken::Cmd
- Defined in:
- lib/shuriken/cmd.rb
Instance Attribute Summary collapse
-
#engine ⇒ Object
Returns the value of attribute engine.
-
#random_mode ⇒ Object
Returns the value of attribute random_mode.
Instance Method Summary collapse
- #args ⇒ Object
- #bench ⇒ Object
- #fen ⇒ Object
- #help ⇒ Object
-
#initialize ⇒ Cmd
constructor
A new instance of Cmd.
- #list ⇒ Object
- #mbench ⇒ Object
- #name ⇒ Object
- #perft ⇒ Object
- #profile ⇒ Object
- #randommode ⇒ Object
- #rubybench ⇒ Object
- #run_suite(depth = 4) ⇒ Object
- #stats ⇒ Object
- #tactics ⇒ Object
- #test ⇒ Object
- #variant ⇒ Object
- #xboard ⇒ Object
Constructor Details
#initialize ⇒ Cmd
Returns a new instance of Cmd.
12 13 14 15 16 17 |
# File 'lib/shuriken/cmd.rb', line 12 def initialize @variant = "caparandom" # default @random_mode = false @tokens = Tokens.new(ARGV) @fen = nil#"rnbqckabnr/pppppppppp/10/10/10/10/PPPPPPPPPP/RNBQCKABNR w KQkq - 0 1" end |
Instance Attribute Details
#engine ⇒ Object
Returns the value of attribute engine.
10 11 12 |
# File 'lib/shuriken/cmd.rb', line 10 def engine @engine end |
#random_mode ⇒ Object
Returns the value of attribute random_mode.
10 11 12 |
# File 'lib/shuriken/cmd.rb', line 10 def random_mode @random_mode end |
Instance Method Details
#args ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/shuriken/cmd.rb', line 144 def args help && return if ARGV.length < 1 while @tokens.ok? case @tokens.cur when "-xboard" then # enter xboard mode xboard and return when "-mbench" then mbench when "-rubybench" then rubybench when "-bench" then bench when "-stats" then stats when "-variant" then variant when "-randommode" then randommode when "-tactics" then tactics when "-test" then test when "-name" then name when "-fen" then fen when "-profile" then profile when "-list" then list when "-help" then help else puts "Shuriken Error: Unknown Command: '#{@tokens.cur}'" return end @tokens.forward end end |
#bench ⇒ Object
59 60 61 62 |
# File 'lib/shuriken/cmd.rb', line 59 def bench e = Shuriken::EngineCaparandom.new(@variant, random_mode: @random_mode) e.bench end |
#fen ⇒ Object
80 81 82 83 |
# File 'lib/shuriken/cmd.rb', line 80 def fen @tokens.go_next @fen = @tokens.cur end |
#help ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/shuriken/cmd.rb', line 126 def help puts "Usage: ruby shuriken.rb [OPTION]... [PARAMS]..." puts "-help: This Help" puts "-xboard: Enter Xboard Mode" puts "-tactics: Run Tactics" puts "-name: Print Name Tactics" puts "-rubybench: Benchmark Ruby" puts "-bench: Benchmark Shuriken Engine" puts "-mbench: Benchmark Shuriken Movegen" puts "-profile: Profile Shuriken" puts "-variant [NAME]: Set Variant (gothic / caparandom / falcon / capablanca)" puts "-randommode: Activate Random Mode" puts "-fen [FEN]: Set Fen" puts "-stats [NUM]: Statistical Analysis" puts "-list: List Moves" puts "-perft [NUM]: Run Perft" end |
#list ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/shuriken/cmd.rb', line 91 def list board = Shuriken::BoardCaparandom.new(@variant) board.use_fen(@fen) mgen = board.mgen_generator moves = mgen.generate_moves i = 0 moves.each do |b| puts "> #{i}: #{b.move_str}" i += 1 end end |
#mbench ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/shuriken/cmd.rb', line 38 def mbench depth = 4 val = @tokens.peek(1) if val != nil && val.match(/\d+/) @tokens.forward depth = @tokens.cur.to_i end run_suite(depth) end |
#name ⇒ Object
19 20 21 |
# File 'lib/shuriken/cmd.rb', line 19 def name puts "#{Shuriken::NAME} v#{Shuriken::VERSION} by #{Shuriken::AUTHOR}" end |
#perft ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/shuriken/cmd.rb', line 48 def perft depth = 3 val = @tokens.peek(1) if val != nil && val.match(/\d+/) @tokens.forward depth = @tokens.cur.to_i end p = PerftCaparandom.new(@variant, @fen) p.perft(depth) end |
#profile ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/shuriken/cmd.rb', line 116 def profile require 'ruby-prof' result = RubyProf.profile do e = Shuriken::EngineCaparandom.new("gothic", random_mode: @random_mode) e.bench end printer = RubyProf::FlatPrinter.new(result) printer.print(STDOUT) end |
#randommode ⇒ Object
34 35 36 |
# File 'lib/shuriken/cmd.rb', line 34 def randommode @random_mode = true end |
#rubybench ⇒ Object
107 108 109 |
# File 'lib/shuriken/cmd.rb', line 107 def rubybench Shuriken::Bench.go end |
#run_suite(depth = 4) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shuriken/cmd.rb', line 23 def run_suite(depth = 4) case @variant when "gothic" Shuriken::PerftGothicCaparandom.new when "falcon" Shuriken::PerftFalconCaparandom.new else Shuriken::PerftCapablancaCaparandom.new end.suite([0, depth].max) end |
#stats ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/shuriken/cmd.rb', line 64 def stats n = 100 val = @tokens.peek(1) if val != nil && val.match(/\d+/) @tokens.forward n = val.to_i end e = Shuriken::EngineCaparandom.new("falcon", random_mode: @random_mode) e.board.use_fen(@fen) if @fen != nil e.stats(n) end |
#tactics ⇒ Object
76 77 78 |
# File 'lib/shuriken/cmd.rb', line 76 def tactics Shuriken::TacticsCaparandom.run end |
#test ⇒ Object
103 104 105 |
# File 'lib/shuriken/cmd.rb', line 103 def test # ... end |
#variant ⇒ Object
85 86 87 88 89 |
# File 'lib/shuriken/cmd.rb', line 85 def variant @tokens.go_next fail "Bad Input" unless @tokens.ok? @variant = @tokens.cur end |
#xboard ⇒ Object
111 112 113 114 |
# File 'lib/shuriken/cmd.rb', line 111 def xboard xboard = Shuriken::Xboard.new(@variant, @random_mode) xboard.go end |