osl 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +42 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/ext/osl/extconf.rb +5 -0
- data/ext/osl/rbosl.cpp +18 -0
- data/ext/osl/rbosl_move.cpp +44 -0
- data/ext/osl/rbosl_move.h +16 -0
- data/ext/osl/rbosl_state.cpp +16 -0
- data/ext/osl/rbosl_state.h +16 -0
- data/ext/osl/rbosl_state_numEffectState.cpp +132 -0
- data/ext/osl/rbosl_state_simpleState.cpp +45 -0
- data/lib/osl.rb +2 -0
- data/lib/osl/version.rb +3 -0
- data/osl.gemspec +24 -0
- data/sample/random_play.rb +40 -0
- data/test/run-test.rb +11 -0
- data/test/test-move.rb +13 -0
- data/test/test-numEffectState.rb +55 -0
- data/test/test-osl.rb +7 -0
- data/test/test-simpleState.rb +7 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aa47dc0d996fd2dbf774dd4158a7823b74a852f5
|
4
|
+
data.tar.gz: 55bf9c91650afa603fd95ea6ba772e7c1f88d837
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2289f3568d9fb26d0af7eefa928b4e15744594a1890c8a2d287be63ebd6353d06d64679d54e362baa957a8b642de99faafe596a0dc33292858094c89dc3feacb
|
7
|
+
data.tar.gz: 79e86f7e2c5bcdb1d9d409ae6f18de41a8bf79bbf5ccc2950e51ff90350ff5e29818224fe9328f16c5dd13354daf70451616eaac1d518ffb8aeda25aff08591f
|
data/.gitignore
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# C++
|
2
|
+
## Compiled Object files
|
3
|
+
*.slo
|
4
|
+
*.lo
|
5
|
+
*.o
|
6
|
+
|
7
|
+
## Compiled Dynamic libraries
|
8
|
+
*.so
|
9
|
+
*.dylib
|
10
|
+
|
11
|
+
## Compiled Static libraries
|
12
|
+
*.lai
|
13
|
+
*.la
|
14
|
+
*.a
|
15
|
+
|
16
|
+
## extconf.rb
|
17
|
+
mkmf.log
|
18
|
+
|
19
|
+
## Make
|
20
|
+
Makefile
|
21
|
+
|
22
|
+
# RubyGems
|
23
|
+
*.gem
|
24
|
+
*.rbc
|
25
|
+
.bundle
|
26
|
+
.config
|
27
|
+
.yardoc
|
28
|
+
Gemfile.lock
|
29
|
+
InstalledFiles
|
30
|
+
_yardoc
|
31
|
+
coverage
|
32
|
+
doc/
|
33
|
+
lib/bundler/man
|
34
|
+
pkg
|
35
|
+
rdoc
|
36
|
+
spec/reports
|
37
|
+
test/tmp
|
38
|
+
test/version_tmp
|
39
|
+
tmp
|
40
|
+
|
41
|
+
# Debug
|
42
|
+
core
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Masafumi Yokoyama
|
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,39 @@
|
|
1
|
+
# Ruby/OSL
|
2
|
+
|
3
|
+
Ruby/OSL is a Ruby binding of OpenShogiLib.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
* OpenShogiLib
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
To install the required libraries:
|
12
|
+
|
13
|
+
* Debian GNU/Linux, Ubuntu
|
14
|
+
|
15
|
+
sudo apt-get install libosl-dev
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'osl'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install osl
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
See samples.
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ext/osl/extconf.rb
ADDED
data/ext/osl/rbosl.cpp
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "rbosl_state.h"
|
3
|
+
#include "rbosl_move.h"
|
4
|
+
|
5
|
+
#ifdef __cplusplus
|
6
|
+
extern "C" {
|
7
|
+
#endif
|
8
|
+
void
|
9
|
+
Init_osl(void)
|
10
|
+
{
|
11
|
+
static VALUE mOsl;
|
12
|
+
mOsl = rb_define_module("Osl");
|
13
|
+
rbosl_state_init(mOsl);
|
14
|
+
rbosl_move_init(mOsl);
|
15
|
+
}
|
16
|
+
#ifdef __cplusplus
|
17
|
+
} /* extern "C" */
|
18
|
+
#endif
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "rbosl_move.h"
|
3
|
+
#include <osl/move.h>
|
4
|
+
#include <osl/record/csa.h>
|
5
|
+
|
6
|
+
VALUE cMove;
|
7
|
+
|
8
|
+
using namespace osl;
|
9
|
+
|
10
|
+
void
|
11
|
+
rbosl_move_free(Move* ptr)
|
12
|
+
{
|
13
|
+
ptr->~Move();
|
14
|
+
ruby_xfree(ptr);
|
15
|
+
}
|
16
|
+
|
17
|
+
static VALUE
|
18
|
+
rbosl_move_s_new(VALUE self)
|
19
|
+
{
|
20
|
+
Move* ptr = new Move();
|
21
|
+
return Data_Wrap_Struct(self, NULL, rbosl_move_free, ptr);
|
22
|
+
}
|
23
|
+
|
24
|
+
static VALUE
|
25
|
+
rbosl_move_to_csa(VALUE self)
|
26
|
+
{
|
27
|
+
Move* ptr;
|
28
|
+
Data_Get_Struct(self, Move, ptr);
|
29
|
+
return rb_str_new2(record::csa::show(*ptr).c_str());
|
30
|
+
}
|
31
|
+
|
32
|
+
#ifdef __cplusplus
|
33
|
+
extern "C" {
|
34
|
+
#endif
|
35
|
+
void
|
36
|
+
rbosl_move_init(VALUE mOsl)
|
37
|
+
{
|
38
|
+
cMove = rb_define_class_under(mOsl, "Move", rb_cObject);
|
39
|
+
rb_define_singleton_method(cMove, "new", RUBY_METHOD_FUNC(rbosl_move_s_new), 0);
|
40
|
+
rb_define_method(cMove, "to_csa", RUBY_METHOD_FUNC(rbosl_move_to_csa), 0);
|
41
|
+
}
|
42
|
+
#ifdef __cplusplus
|
43
|
+
} /* extern "C" */
|
44
|
+
#endif
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#ifndef RBOSL_MOVE_H
|
2
|
+
#define RBOSL_MOVE_H
|
3
|
+
|
4
|
+
#include "ruby.h"
|
5
|
+
|
6
|
+
extern VALUE cMove;
|
7
|
+
|
8
|
+
#ifdef __cplusplus
|
9
|
+
extern "C" {
|
10
|
+
#endif
|
11
|
+
extern void rbosl_move_init(VALUE mOsl);
|
12
|
+
#ifdef __cplusplus
|
13
|
+
} /* extern "C" */
|
14
|
+
#endif
|
15
|
+
|
16
|
+
#endif /* RBOSL_MOVE_H */
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#include "rbosl_state.h"
|
2
|
+
|
3
|
+
#ifdef __cplusplus
|
4
|
+
extern "C" {
|
5
|
+
#endif
|
6
|
+
void
|
7
|
+
rbosl_state_init(VALUE mOsl)
|
8
|
+
{
|
9
|
+
static VALUE mState;
|
10
|
+
mState = rb_define_module_under(mOsl, "State");
|
11
|
+
rbosl_simpleState_init(mState);
|
12
|
+
rbosl_numEffectState_init(mState);
|
13
|
+
}
|
14
|
+
#ifdef __cplusplus
|
15
|
+
} /* extern "C" */
|
16
|
+
#endif
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#ifndef RBOSL_STATE_H
|
2
|
+
#define RBOSL_STATE_H
|
3
|
+
|
4
|
+
#include "ruby.h"
|
5
|
+
|
6
|
+
#ifdef __cplusplus
|
7
|
+
extern "C" {
|
8
|
+
#endif
|
9
|
+
extern void rbosl_state_init(VALUE mOsl);
|
10
|
+
extern void rbosl_simpleState_init(VALUE mState);
|
11
|
+
extern void rbosl_numEffectState_init(VALUE mState);
|
12
|
+
#ifdef __cplusplus
|
13
|
+
} /* extern "C" */
|
14
|
+
#endif
|
15
|
+
|
16
|
+
#endif /* RBOSL_STATE_H */
|
@@ -0,0 +1,132 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "rbosl_state.h"
|
3
|
+
#include "rbosl_move.h"
|
4
|
+
#include <osl/state/numEffectState.h>
|
5
|
+
#include <osl/handicap.h>
|
6
|
+
#include <osl/container/moveVector.h>
|
7
|
+
#include <osl/move_generator/legalMoves.h>
|
8
|
+
#include <osl/record/csa.h>
|
9
|
+
#include <iostream>
|
10
|
+
|
11
|
+
using namespace osl;
|
12
|
+
|
13
|
+
void
|
14
|
+
rbosl_numEffectState_free(state::NumEffectState* ptr)
|
15
|
+
{
|
16
|
+
ptr->~NumEffectState();
|
17
|
+
ruby_xfree(ptr);
|
18
|
+
}
|
19
|
+
|
20
|
+
static VALUE
|
21
|
+
rbosl_numEffectState_s_new(VALUE self)
|
22
|
+
{
|
23
|
+
state::NumEffectState* ptr = new state::NumEffectState(state::SimpleState(HIRATE));
|
24
|
+
// TODO: support GC
|
25
|
+
//return Data_Wrap_Struct(self, NULL, rbosl_numEffectState_free, ptr);
|
26
|
+
return Data_Wrap_Struct(self, NULL, NULL, ptr);
|
27
|
+
}
|
28
|
+
|
29
|
+
static VALUE
|
30
|
+
rbosl_numEffectState_show(VALUE self)
|
31
|
+
{
|
32
|
+
state::NumEffectState* p;
|
33
|
+
Data_Get_Struct(self, state::NumEffectState, p);
|
34
|
+
std::cout << *p << std::endl;
|
35
|
+
return Qnil;
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE
|
39
|
+
rbosl_numEffectState_generate(VALUE self)
|
40
|
+
{
|
41
|
+
state::NumEffectState* p;
|
42
|
+
Data_Get_Struct(self, state::NumEffectState, p);
|
43
|
+
MoveVector moves;
|
44
|
+
LegalMoves::generate(*p, moves);
|
45
|
+
VALUE moves_ary = rb_ary_new();
|
46
|
+
for (int i = 0; i < (int)moves.size(); i++) {
|
47
|
+
// TODO: ruby: munmap_chunk(): invalid pointer
|
48
|
+
//VALUE move = Data_Wrap_Struct(cMove, NULL, rbosl_move_free, &moves[i]);
|
49
|
+
VALUE move = Data_Wrap_Struct(cMove, NULL, NULL, &moves[i]);
|
50
|
+
rb_ary_push(moves_ary, move);
|
51
|
+
}
|
52
|
+
return moves_ary;
|
53
|
+
}
|
54
|
+
|
55
|
+
static VALUE
|
56
|
+
rbosl_numEffectState_makeMove(VALUE self, VALUE rb_move)
|
57
|
+
{
|
58
|
+
state::NumEffectState* p;
|
59
|
+
Data_Get_Struct(self, state::NumEffectState, p);
|
60
|
+
|
61
|
+
Move* c_move;
|
62
|
+
if (TYPE(rb_move) == T_STRING) {
|
63
|
+
Move osl_move = record::csa::strToMove(StringValuePtr(rb_move), *p);
|
64
|
+
c_move = &osl_move;
|
65
|
+
} else {
|
66
|
+
Data_Get_Struct(rb_move, Move, c_move);
|
67
|
+
}
|
68
|
+
|
69
|
+
p->makeMove(*c_move);
|
70
|
+
|
71
|
+
return Qnil;
|
72
|
+
}
|
73
|
+
|
74
|
+
static VALUE
|
75
|
+
rbosl_numEffectState_isValidMove(VALUE self, VALUE rb_move)
|
76
|
+
{
|
77
|
+
state::NumEffectState* p;
|
78
|
+
Data_Get_Struct(self, state::NumEffectState, p);
|
79
|
+
|
80
|
+
Move* c_move;
|
81
|
+
if (TYPE(rb_move) == T_STRING) {
|
82
|
+
// TODO: format check
|
83
|
+
if (strlen(StringValuePtr(rb_move)) == 0) {
|
84
|
+
return Qfalse;
|
85
|
+
}
|
86
|
+
Move osl_move = record::csa::strToMove(StringValuePtr(rb_move), *p);
|
87
|
+
c_move = &osl_move;
|
88
|
+
} else {
|
89
|
+
Data_Get_Struct(rb_move, Move, c_move);
|
90
|
+
}
|
91
|
+
|
92
|
+
if (p->isValidMove(*c_move)) {
|
93
|
+
return Qtrue;
|
94
|
+
} else {
|
95
|
+
return Qfalse;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
static VALUE
|
100
|
+
rbosl_numEffectState_inCheck(VALUE self)
|
101
|
+
{
|
102
|
+
state::NumEffectState* p;
|
103
|
+
Data_Get_Struct(self, state::NumEffectState, p);
|
104
|
+
|
105
|
+
if (p->inCheck(alt(p->turn()))) {
|
106
|
+
return Qtrue;
|
107
|
+
} else {
|
108
|
+
return Qfalse;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
#ifdef __cplusplus
|
113
|
+
extern "C" {
|
114
|
+
#endif
|
115
|
+
void
|
116
|
+
rbosl_numEffectState_init(VALUE mState)
|
117
|
+
{
|
118
|
+
VALUE cNumEffectState;
|
119
|
+
cNumEffectState = rb_define_class_under(mState, "NumEffectState", rb_cObject);
|
120
|
+
rb_define_singleton_method(cNumEffectState, "new", RUBY_METHOD_FUNC(rbosl_numEffectState_s_new), 0);
|
121
|
+
rb_define_method(cNumEffectState, "show", RUBY_METHOD_FUNC(rbosl_numEffectState_show), 0);
|
122
|
+
rb_define_method(cNumEffectState, "generate", RUBY_METHOD_FUNC(rbosl_numEffectState_generate), 0);
|
123
|
+
rb_define_method(cNumEffectState, "makeMove", RUBY_METHOD_FUNC(rbosl_numEffectState_makeMove), 1);
|
124
|
+
rb_define_alias(cNumEffectState, "move", "makeMove");
|
125
|
+
rb_define_method(cNumEffectState, "inCheck", RUBY_METHOD_FUNC(rbosl_numEffectState_inCheck), 0);
|
126
|
+
rb_define_alias(cNumEffectState, "in_check?", "inCheck");
|
127
|
+
rb_define_method(cNumEffectState, "isValidMove", RUBY_METHOD_FUNC(rbosl_numEffectState_isValidMove), 1);
|
128
|
+
rb_define_alias(cNumEffectState, "valid?", "isValidMove");
|
129
|
+
}
|
130
|
+
#ifdef __cplusplus
|
131
|
+
} /* extern "C" */
|
132
|
+
#endif
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "rbosl_state.h"
|
3
|
+
#include <osl/state/simpleState.h>
|
4
|
+
#include <osl/handicap.h>
|
5
|
+
#include <iostream>
|
6
|
+
|
7
|
+
using namespace osl;
|
8
|
+
|
9
|
+
void
|
10
|
+
rbosl_simpleState_free(state::SimpleState* ptr)
|
11
|
+
{
|
12
|
+
ptr->~SimpleState();
|
13
|
+
ruby_xfree(ptr);
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
rbosl_simpleState_s_new(VALUE self)
|
18
|
+
{
|
19
|
+
state::SimpleState* ptr = new state::SimpleState(HIRATE);
|
20
|
+
return Data_Wrap_Struct(self, NULL, rbosl_simpleState_free, ptr);
|
21
|
+
}
|
22
|
+
|
23
|
+
static VALUE
|
24
|
+
rbosl_simpleState_show(VALUE self)
|
25
|
+
{
|
26
|
+
state::SimpleState* ptr;
|
27
|
+
Data_Get_Struct(self, state::SimpleState, ptr);
|
28
|
+
std::cout << *ptr << std::endl;
|
29
|
+
return Qnil;
|
30
|
+
}
|
31
|
+
|
32
|
+
#ifdef __cplusplus
|
33
|
+
extern "C" {
|
34
|
+
#endif
|
35
|
+
void
|
36
|
+
rbosl_simpleState_init(VALUE mState)
|
37
|
+
{
|
38
|
+
VALUE cSimpleState;
|
39
|
+
cSimpleState = rb_define_class_under(mState, "SimpleState", rb_cObject);
|
40
|
+
rb_define_singleton_method(cSimpleState, "new", RUBY_METHOD_FUNC(rbosl_simpleState_s_new), 0);
|
41
|
+
rb_define_method(cSimpleState, "show", RUBY_METHOD_FUNC(rbosl_simpleState_show), 0);
|
42
|
+
}
|
43
|
+
#ifdef __cplusplus
|
44
|
+
} /* extern "C" */
|
45
|
+
#endif
|
data/lib/osl.rb
ADDED
data/lib/osl/version.rb
ADDED
data/osl.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'osl/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "osl"
|
8
|
+
spec.version = Osl::VERSION
|
9
|
+
spec.authors = ["Masafumi Yokoyama"]
|
10
|
+
spec.email = ["myokoym@gmail.com"]
|
11
|
+
spec.description = %q{Ruby/OSL is a Ruby binding of OpenShogiLib.}
|
12
|
+
spec.summary = %q{Ruby/OSL is a Ruby binding of OpenShogiLib.}
|
13
|
+
spec.homepage = "https://github.com/myokoym/ruby-osl"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.extensions = ["ext/osl/extconf.rb"]
|
20
|
+
spec.require_paths = ["lib", "ext/osl"]
|
21
|
+
|
22
|
+
spec.add_development_dependency("bundler", "~> 1.3")
|
23
|
+
spec.add_development_dependency("rake")
|
24
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "osl"
|
4
|
+
|
5
|
+
state = Osl::State::NumEffectState.new
|
6
|
+
|
7
|
+
loop do
|
8
|
+
# my turn
|
9
|
+
moves = state.generate
|
10
|
+
if moves.empty?
|
11
|
+
puts "make masita"
|
12
|
+
break
|
13
|
+
end
|
14
|
+
my_move = moves.sample
|
15
|
+
state.move(my_move)
|
16
|
+
|
17
|
+
state.show
|
18
|
+
puts my_move.to_csa
|
19
|
+
|
20
|
+
if state.in_check?
|
21
|
+
puts "checkmate!"
|
22
|
+
break
|
23
|
+
end
|
24
|
+
|
25
|
+
# your turn
|
26
|
+
op_move = nil
|
27
|
+
loop do
|
28
|
+
line = gets.chomp
|
29
|
+
if state.valid?(line)
|
30
|
+
op_move = line
|
31
|
+
break
|
32
|
+
end
|
33
|
+
puts "Invalid move. Please retry."
|
34
|
+
end
|
35
|
+
|
36
|
+
state.move(op_move)
|
37
|
+
|
38
|
+
state.show
|
39
|
+
puts op_move
|
40
|
+
end
|
data/test/run-test.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "test-unit"
|
4
|
+
require "test/unit/notify"
|
5
|
+
require "test/unit/rr"
|
6
|
+
|
7
|
+
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
8
|
+
$LOAD_PATH.unshift(File.join(base_dir, "lib"))
|
9
|
+
$LOAD_PATH.unshift(File.join(base_dir, "test"))
|
10
|
+
|
11
|
+
exit Test::Unit::AutoRunner.run(true)
|
data/test/test-move.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "osl"
|
2
|
+
|
3
|
+
class MoveTest < Test::Unit::TestCase
|
4
|
+
def test_new
|
5
|
+
assert_not_nil(Osl::Move.new)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_to_csa
|
9
|
+
assert_true(Osl::Move.new.to_csa.is_a?(String))
|
10
|
+
nstate = Osl::State::NumEffectState.new
|
11
|
+
assert_match(/\+[0-9]{4}[A-Z]{2}/, nstate.generate.first.to_csa)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "osl"
|
2
|
+
|
3
|
+
class NumEffectStateTest < Test::Unit::TestCase
|
4
|
+
def test_new
|
5
|
+
assert_not_nil(Osl::State::NumEffectState.new)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_generate
|
9
|
+
nstate = Osl::State::NumEffectState.new
|
10
|
+
moves = nstate.generate
|
11
|
+
assert_not_nil(moves)
|
12
|
+
assert_true(moves.is_a?(Array))
|
13
|
+
assert_true(moves.first.is_a?(Osl::Move))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_makeMove
|
17
|
+
nstate = Osl::State::NumEffectState.new
|
18
|
+
moves = nstate.generate
|
19
|
+
assert_nothing_raised do
|
20
|
+
nstate.makeMove(moves.first)
|
21
|
+
end
|
22
|
+
assert_nothing_raised do
|
23
|
+
nstate.move(moves.first) # alias
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_makeMove_from_csa
|
28
|
+
nstate = Osl::State::NumEffectState.new
|
29
|
+
assert_nothing_raised do
|
30
|
+
nstate.makeMove("+7776FU")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_isValidMove
|
35
|
+
nstate = Osl::State::NumEffectState.new
|
36
|
+
moves = nstate.generate
|
37
|
+
assert_true(nstate.isValidMove(moves.first))
|
38
|
+
assert_true(nstate.valid?(moves.first)) # alias
|
39
|
+
assert_false(nstate.isValidMove(Osl::Move.new))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_isValidMove_from_csa
|
43
|
+
nstate = Osl::State::NumEffectState.new
|
44
|
+
assert_true(nstate.isValidMove("+7776FU"))
|
45
|
+
assert_true(nstate.valid?("+7776FU")) # alias
|
46
|
+
assert_false(nstate.isValidMove("-7776FU"))
|
47
|
+
assert_false(nstate.isValidMove(""))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_inCheck
|
51
|
+
nstate = Osl::State::NumEffectState.new
|
52
|
+
assert_false(nstate.inCheck)
|
53
|
+
assert_false(nstate.in_check?) # alias
|
54
|
+
end
|
55
|
+
end
|
data/test/test-osl.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: osl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masafumi Yokoyama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Ruby/OSL is a Ruby binding of OpenShogiLib.
|
42
|
+
email:
|
43
|
+
- myokoym@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions:
|
46
|
+
- ext/osl/extconf.rb
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- ext/osl/extconf.rb
|
55
|
+
- ext/osl/rbosl.cpp
|
56
|
+
- ext/osl/rbosl_move.cpp
|
57
|
+
- ext/osl/rbosl_move.h
|
58
|
+
- ext/osl/rbosl_state.cpp
|
59
|
+
- ext/osl/rbosl_state.h
|
60
|
+
- ext/osl/rbosl_state_numEffectState.cpp
|
61
|
+
- ext/osl/rbosl_state_simpleState.cpp
|
62
|
+
- lib/osl.rb
|
63
|
+
- lib/osl/version.rb
|
64
|
+
- osl.gemspec
|
65
|
+
- sample/random_play.rb
|
66
|
+
- test/run-test.rb
|
67
|
+
- test/test-move.rb
|
68
|
+
- test/test-numEffectState.rb
|
69
|
+
- test/test-osl.rb
|
70
|
+
- test/test-simpleState.rb
|
71
|
+
homepage: https://github.com/myokoym/ruby-osl
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
- ext/osl
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.3
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Ruby/OSL is a Ruby binding of OpenShogiLib.
|
96
|
+
test_files:
|
97
|
+
- test/run-test.rb
|
98
|
+
- test/test-move.rb
|
99
|
+
- test/test-numEffectState.rb
|
100
|
+
- test/test-osl.rb
|
101
|
+
- test/test-simpleState.rb
|
102
|
+
has_rdoc:
|