quizgame 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +15 -5
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/bin/quizgame +4 -5
- data/lib/quizgame.rb +163 -0
- data/lib/quizgame/problem.rb +8 -8
- data/quizgame.gemspec +6 -7
- data/test/test_problem.rb +4 -6
- data/test/test_quizgame.rb +14 -7
- metadata +17 -48
- data/lib/quizgame/quizgame.rb +0 -144
data/CHANGES
CHANGED
@@ -1,16 +1,26 @@
|
|
1
1
|
= quizgame Changelog
|
2
2
|
|
3
3
|
== Master (for 0.0.4)
|
4
|
+
- Adjust to builtinextension-0.1.0.
|
5
|
+
- Show histgram of weight file after run quizgame.
|
6
|
+
- Change default filename extensions;
|
7
|
+
for problems from ".yaml" to ".quiz",
|
8
|
+
and weights from "_wts.yaml" to ".wts".
|
9
|
+
- Problem to QuizGame::Problem
|
10
|
+
- History style is changed;
|
11
|
+
from "[1 correct / 2 problems / 3 norma]" to "ox-"
|
4
12
|
|
5
13
|
== Version 0.0.3
|
6
|
-
Adjust to
|
14
|
+
- Adjust to weightedpicker-0.1.0.
|
7
15
|
|
8
16
|
== Version 0.0.2
|
9
|
-
bin/quizgame raise error when _wts.yaml includes
|
10
|
-
|
17
|
+
- bin/quizgame raise error when _wts.yaml includes
|
18
|
+
a float weight.
|
19
|
+
- fix the bug when NaN occur with quit when no problem
|
20
|
+
is answered.
|
11
21
|
|
12
22
|
== Version 0.0.1
|
13
|
-
bugfix
|
23
|
+
- bugfix
|
14
24
|
|
15
25
|
== Version 0.0.0
|
16
|
-
initiali release.
|
26
|
+
- initiali release.
|
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/bin/quizgame
CHANGED
@@ -33,9 +33,7 @@ require "pp"
|
|
33
33
|
require "optparse"
|
34
34
|
|
35
35
|
require "rubygems"
|
36
|
-
|
37
|
-
require "quizgame/quizgame.rb"
|
38
|
-
require "quizgame/problem.rb"
|
36
|
+
require "quizgame"
|
39
37
|
|
40
38
|
# option analysis
|
41
39
|
#default value
|
@@ -54,9 +52,10 @@ data = YAML.load_file(ARGV[0])
|
|
54
52
|
requirement = data["requirement"]
|
55
53
|
problems = {}
|
56
54
|
data["problems"].each do |id, ary|
|
57
|
-
problems[id] = Problem.new(*ary)
|
55
|
+
problems[id] = QuizGame::Problem.new(*ary)
|
58
56
|
end
|
59
|
-
weight_yaml = ARGV[0].sub(/\.yaml$/, "_wts.yaml")
|
57
|
+
#weight_yaml = ARGV[0].sub(/\.yaml$/, "_wts.yaml")
|
58
|
+
weight_yaml = ARGV[0].sub(/\.quiz$/, ".wts")
|
60
59
|
|
61
60
|
game = QuizGame.new(requirement, problems, weight_yaml)
|
62
61
|
game.run(OPTIONS[:norma])
|
data/lib/quizgame.rb
CHANGED
@@ -0,0 +1,163 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
class QuizGame; end
|
5
|
+
|
6
|
+
require "yaml"
|
7
|
+
require "rubygems"
|
8
|
+
require "weightedpicker"
|
9
|
+
require "quizgame/problem"
|
10
|
+
|
11
|
+
gem "builtinextension"
|
12
|
+
require "string/color.rb"
|
13
|
+
require "string/mismatch.rb"
|
14
|
+
|
15
|
+
include Math
|
16
|
+
|
17
|
+
# クイズゲームを管理・実行するクラス。
|
18
|
+
class QuizGame
|
19
|
+
QUIT_STR = "q"
|
20
|
+
#NEXT_STR = ""
|
21
|
+
NUM_EMPTY_LINE = 1
|
22
|
+
#MINIMUM_INTERVAL = 10 #同じ問題を再出題する最短の interval
|
23
|
+
|
24
|
+
class QuizGame::NoQuizError < Exception; end
|
25
|
+
|
26
|
+
# クイズデータを読み込む。
|
27
|
+
def initialize(requirement, problems, picker_file)
|
28
|
+
@requirement = requirement
|
29
|
+
@problems = problems
|
30
|
+
@weight_file = picker_file
|
31
|
+
end
|
32
|
+
|
33
|
+
# 条件を満たすまでクイズを実行。
|
34
|
+
# norma は終了条件の数
|
35
|
+
def run(norma)
|
36
|
+
begin
|
37
|
+
picker = WeightedPicker.load_file @weight_file
|
38
|
+
picker.merge @problems.keys
|
39
|
+
rescue WeightedPicker::InvalidWeightError
|
40
|
+
puts "Error!"
|
41
|
+
puts "#{@weight_file} contains float weight. Use integers as weights."
|
42
|
+
exit
|
43
|
+
rescue Errno::ENOENT
|
44
|
+
#puts "TEST"
|
45
|
+
picker = WeightedPicker.new({})
|
46
|
+
picker.merge @problems.keys
|
47
|
+
end
|
48
|
+
|
49
|
+
history = Array.new(norma)
|
50
|
+
problem_count = 0
|
51
|
+
show_statement(norma)
|
52
|
+
puts "Requirement: ", @requirement
|
53
|
+
|
54
|
+
start_time = Time.new
|
55
|
+
|
56
|
+
while (problem_count < norma )
|
57
|
+
id = picker.pick
|
58
|
+
problem = @problems[id]
|
59
|
+
|
60
|
+
puts "-"*60
|
61
|
+
print "[Q.#{problem_count+1}, #{id}] "
|
62
|
+
problem.exhibit_question
|
63
|
+
|
64
|
+
input_str = user_input
|
65
|
+
(puts "-- Interrupted --"; break) if (input_str == QUIT_STR)
|
66
|
+
#(puts "-- Next --"; next) if (input_str == NEXT_STR)
|
67
|
+
|
68
|
+
problem_count += 1
|
69
|
+
result = problem.correct?(input_str)
|
70
|
+
history[problem_count -1] = result
|
71
|
+
if result
|
72
|
+
picker.lighten(id)
|
73
|
+
else
|
74
|
+
picker.weigh(id)
|
75
|
+
end
|
76
|
+
|
77
|
+
puts show_result(problem, input_str)
|
78
|
+
puts problem.show_supplement
|
79
|
+
print "History: "
|
80
|
+
show_history(history)
|
81
|
+
end
|
82
|
+
|
83
|
+
File.open(@weight_file, "w"){|io| picker.dump(io) }
|
84
|
+
|
85
|
+
puts "="*60
|
86
|
+
sleep(0.35) #Visual effect. A little stop before showing results.
|
87
|
+
if ((history.count(true) == norma) && norma > 0)
|
88
|
+
show_great
|
89
|
+
end
|
90
|
+
|
91
|
+
printf("result: [%d correct / %d problems]",
|
92
|
+
history.count(true), problem_count)
|
93
|
+
|
94
|
+
begin
|
95
|
+
printf(" %2d\%\n", ( (history.count(true).to_f)/ problem_count*100).to_i)
|
96
|
+
rescue FloatDomainError
|
97
|
+
puts " No problem is answered."
|
98
|
+
end
|
99
|
+
|
100
|
+
print "Time: ", Time.now - start_time, "\n"
|
101
|
+
|
102
|
+
puts
|
103
|
+
picker.dump_histgram($stdout)
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def show_history(results, io = $stdout)
|
109
|
+
str = results.map do |result|
|
110
|
+
if result == true
|
111
|
+
"o"
|
112
|
+
elsif result == false
|
113
|
+
"x"
|
114
|
+
elsif result == nil
|
115
|
+
"-"
|
116
|
+
else
|
117
|
+
raise "Must not happen!"
|
118
|
+
end
|
119
|
+
end . join("")
|
120
|
+
io.puts str
|
121
|
+
end
|
122
|
+
|
123
|
+
#ゲーム開始前に情報を提示。
|
124
|
+
def show_statement(norma, io = $stdout)
|
125
|
+
io.puts "#{QUIT_STR}[Enter] for immediately quit."
|
126
|
+
io.puts
|
127
|
+
io.puts "This program has #{@problems.size} problems."
|
128
|
+
io.print "Norma: " + norma.to_s.color(:green) + " "
|
129
|
+
io.puts "problems."
|
130
|
+
end
|
131
|
+
|
132
|
+
def user_input(input = STDIN, output = $stdout)
|
133
|
+
output.print "\n" * NUM_EMPTY_LINE
|
134
|
+
output.print "input: "
|
135
|
+
return input.gets.chomp!
|
136
|
+
end
|
137
|
+
|
138
|
+
#
|
139
|
+
def show_result(problem, str, io = $stdout)
|
140
|
+
if (problem.correct?(str) == false)
|
141
|
+
io.puts "×: ".color(:red) + problem.emphasize_wrong(str)
|
142
|
+
end
|
143
|
+
io.puts "○: #{problem.answer}"
|
144
|
+
end
|
145
|
+
|
146
|
+
def show_great
|
147
|
+
print "\n"
|
148
|
+
great = Array.new
|
149
|
+
puts "■■■■■□■■■■■□■■■■■□■■■■■□■■■■■□■□■".color(:red )
|
150
|
+
puts "■□□□□□■□□□■□■□□□□□■□□□■□□□■□□□■□■".color(:yellow)
|
151
|
+
puts "■□■■■□■■■■■□■■■■■□■■■■■□□□■□□□■□■".color(:green )
|
152
|
+
puts "■□□□■□■□□■□□■□□□□□■□□□■□□□■□□□□□□".color(:cyan )
|
153
|
+
puts "■■■■■□■□□□■□■■■■■□■□□□■□□□■□□□■□■".color(:blue )
|
154
|
+
puts
|
155
|
+
puts "All answers are correct!"
|
156
|
+
puts
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
data/lib/quizgame/problem.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
|
4
4
|
require "rubygems"
|
5
5
|
gem "builtinextension"
|
6
|
-
require "
|
7
|
-
require "
|
6
|
+
require "string/color.rb"
|
7
|
+
require "string/mismatch.rb"
|
8
8
|
|
9
9
|
#Class for one item of quizes.
|
10
10
|
#This class does not print to stdout.
|
@@ -27,9 +27,9 @@ require "string_mismatch.rb"
|
|
27
27
|
# 正否に関わらない補足情報が supplement
|
28
28
|
#この用語を使う。
|
29
29
|
#
|
30
|
-
#requirement を Problem 内では保持しない。
|
30
|
+
#requirement を QuizGame::Problem 内では保持しない。
|
31
31
|
#多くの場合、上位の構造で保持して同種の問題を繰り返すものだから。
|
32
|
-
class Problem
|
32
|
+
class QuizGame::Problem
|
33
33
|
attr_reader :question, :answer, :supplement
|
34
34
|
|
35
35
|
def initialize( question, answer, supplement = nil )
|
@@ -39,10 +39,10 @@ class Problem
|
|
39
39
|
end
|
40
40
|
|
41
41
|
#問題文を表示。
|
42
|
-
#Problem 側がこのメソッドを持つことについて。
|
42
|
+
#QuizGame::Problem 側がこのメソッドを持つことについて。
|
43
43
|
#問題が必ずしも文でないことがあるため。
|
44
44
|
#たとえばヒアリングの問題なんかでは、
|
45
|
-
#Problem クラスインスタンスがその再生方法などを持っているべきだ。
|
45
|
+
#QuizGame::Problem クラスインスタンスがその再生方法などを持っているべきだ。
|
46
46
|
def exhibit_question( io = STDOUT )
|
47
47
|
io.puts @question
|
48
48
|
end
|
@@ -57,8 +57,8 @@ class Problem
|
|
57
57
|
end
|
58
58
|
|
59
59
|
#正誤判定。
|
60
|
-
#正誤判定は Problem 内で行う。
|
61
|
-
#Problem のサブクラスで正誤判定条件を変更できる。
|
60
|
+
#正誤判定は QuizGame::Problem 内で行う。
|
61
|
+
#QuizGame::Problem のサブクラスで正誤判定条件を変更できる。
|
62
62
|
#MEMO: 今のところ ignorecase しているが、本来は厳密に一致せんとあかん。
|
63
63
|
def correct?( data )
|
64
64
|
return true if /^#{@answer}$/i =~ data
|
data/quizgame.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "quizgame"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["ippei94da"]
|
12
|
-
s.date = "2013-04-
|
12
|
+
s.date = "2013-04-18"
|
13
13
|
s.description = "This gem privide framework for quiz game. This gem can be used for spaced repetition study. The more frequently mistaken problems are given more frequently."
|
14
14
|
s.email = "ippei94da@gmail.com"
|
15
15
|
s.executables = ["quizgame"]
|
@@ -33,7 +33,6 @@ Gem::Specification.new do |s|
|
|
33
33
|
"example/hyakuninIsshuShort.yaml",
|
34
34
|
"lib/quizgame.rb",
|
35
35
|
"lib/quizgame/problem.rb",
|
36
|
-
"lib/quizgame/quizgame.rb",
|
37
36
|
"quizgame.gemspec",
|
38
37
|
"test/helper.rb",
|
39
38
|
"test/test_problem.rb",
|
@@ -42,7 +41,7 @@ Gem::Specification.new do |s|
|
|
42
41
|
s.homepage = "http://github.com/ippei94da/quizgame"
|
43
42
|
s.licenses = ["MIT"]
|
44
43
|
s.require_paths = ["lib"]
|
45
|
-
s.rubygems_version = "1.8.
|
44
|
+
s.rubygems_version = "1.8.11"
|
46
45
|
s.summary = "Framework for game with quiz format."
|
47
46
|
|
48
47
|
if s.respond_to? :specification_version then
|
@@ -53,14 +52,14 @@ Gem::Specification.new do |s|
|
|
53
52
|
s.add_development_dependency(%q<bundler>, ["~> 1.3.4"])
|
54
53
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
55
54
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
56
|
-
s.add_development_dependency(%q<builtinextension>, [">= 0.
|
55
|
+
s.add_development_dependency(%q<builtinextension>, [">= 0.1.0"])
|
57
56
|
s.add_development_dependency(%q<weightedpicker>, [">= 0.1.0"])
|
58
57
|
else
|
59
58
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
60
59
|
s.add_dependency(%q<bundler>, ["~> 1.3.4"])
|
61
60
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
62
61
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
63
|
-
s.add_dependency(%q<builtinextension>, [">= 0.
|
62
|
+
s.add_dependency(%q<builtinextension>, [">= 0.1.0"])
|
64
63
|
s.add_dependency(%q<weightedpicker>, [">= 0.1.0"])
|
65
64
|
end
|
66
65
|
else
|
@@ -68,7 +67,7 @@ Gem::Specification.new do |s|
|
|
68
67
|
s.add_dependency(%q<bundler>, ["~> 1.3.4"])
|
69
68
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
70
69
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
71
|
-
s.add_dependency(%q<builtinextension>, [">= 0.
|
70
|
+
s.add_dependency(%q<builtinextension>, [">= 0.1.0"])
|
72
71
|
s.add_dependency(%q<weightedpicker>, [">= 0.1.0"])
|
73
72
|
end
|
74
73
|
end
|
data/test/test_problem.rb
CHANGED
@@ -5,14 +5,12 @@ require 'helper'
|
|
5
5
|
require "stringio"
|
6
6
|
require "test/unit"
|
7
7
|
|
8
|
-
require "quizgame/problem.rb"
|
9
|
-
|
10
8
|
class TC_Problem < Test::Unit::TestCase
|
11
9
|
def setup
|
12
|
-
@p00 = Problem.new( "vortex", "vortices", "ラテン系語尾" )
|
13
|
-
@p01 = Problem.new( "これはペンです。", "This is a pen.", "かんたん" )
|
14
|
-
@p02 = Problem.new( "ふ", "むべ", "第22")
|
15
|
-
@p03 = Problem.new( "4 underscore after abc", "abc____" )
|
10
|
+
@p00 = QuizGame::Problem.new( "vortex", "vortices", "ラテン系語尾" )
|
11
|
+
@p01 = QuizGame::Problem.new( "これはペンです。", "This is a pen.", "かんたん" )
|
12
|
+
@p02 = QuizGame::Problem.new( "ふ", "むべ", "第22")
|
13
|
+
@p03 = QuizGame::Problem.new( "4 underscore after abc", "abc____" )
|
16
14
|
end
|
17
15
|
|
18
16
|
def test_exhibit_question
|
data/test/test_quizgame.rb
CHANGED
@@ -5,11 +5,10 @@ require 'helper'
|
|
5
5
|
require "test/unit"
|
6
6
|
require "stringio"
|
7
7
|
require "fileutils"
|
8
|
-
require "quizgame/quizgame.rb"
|
9
8
|
|
10
9
|
class QuizGame
|
11
10
|
attr_accessor :problem_selector, :requirement, :yaml_mtime, :norma
|
12
|
-
public :user_input, :show_result, :show_statement
|
11
|
+
public :user_input, :show_result, :show_statement, :show_history
|
13
12
|
end
|
14
13
|
|
15
14
|
class TC_QuizGame < Test::Unit::TestCase
|
@@ -20,8 +19,8 @@ class TC_QuizGame < Test::Unit::TestCase
|
|
20
19
|
|
21
20
|
requirement = "Answer English spell."
|
22
21
|
problems = {
|
23
|
-
"p1" => Problem.new( "1", "one", "いち" ),
|
24
|
-
"p2" => Problem.new( "2", "two", "に" )
|
22
|
+
"p1" => QuizGame::Problem.new( "1", "one", "いち" ),
|
23
|
+
"p2" => QuizGame::Problem.new( "2", "two", "に" )
|
25
24
|
}
|
26
25
|
@qg00 = QuizGame.new(requirement, problems, QUIZ_FILE)
|
27
26
|
end
|
@@ -37,7 +36,7 @@ class TC_QuizGame < Test::Unit::TestCase
|
|
37
36
|
def test_run
|
38
37
|
#run には WeightedPicker 経由の乱数要素が含まれるので、
|
39
38
|
#妥当なテストが書けない。
|
40
|
-
#
|
39
|
+
#srand セットすればいけそうか。
|
41
40
|
end
|
42
41
|
|
43
42
|
def test_show_statement
|
@@ -62,14 +61,14 @@ class TC_QuizGame < Test::Unit::TestCase
|
|
62
61
|
|
63
62
|
def test_show_result
|
64
63
|
io = StringIO.new
|
65
|
-
@qg00.show_result( Problem.new( "1", "one" , "supplement1" ), "one", io )
|
64
|
+
@qg00.show_result( QuizGame::Problem.new( "1", "one" , "supplement1" ), "one", io )
|
66
65
|
io.rewind
|
67
66
|
assert_equal( "○: one\n", io.readline )
|
68
67
|
assert_raise( EOFError ){ io.readline }
|
69
68
|
io.close
|
70
69
|
|
71
70
|
io = StringIO.new
|
72
|
-
@qg00.show_result( Problem.new( "1", "one" , "supplement1" ), "oo", io )
|
71
|
+
@qg00.show_result( QuizGame::Problem.new( "1", "one" , "supplement1" ), "oo", io )
|
73
72
|
io.rewind
|
74
73
|
assert_equal( "\e[31;49m×: \e[39;49mo\e[31;49mo_\e[39;49m\n", io.readline )
|
75
74
|
assert_equal( "○: one\n", io.readline )
|
@@ -77,5 +76,13 @@ class TC_QuizGame < Test::Unit::TestCase
|
|
77
76
|
io.close
|
78
77
|
end
|
79
78
|
|
79
|
+
def test_show_history
|
80
|
+
history = [true, false, true, nil]
|
81
|
+
io = StringIO.new
|
82
|
+
@qg00.show_history(history, io)
|
83
|
+
io.rewind
|
84
|
+
assert_equal("oxo-\n", io.read)
|
85
|
+
end
|
86
|
+
|
80
87
|
end
|
81
88
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quizgame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &78640980 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,15 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.12'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '3.12'
|
24
|
+
version_requirements: *78640980
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: bundler
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &78640740 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ~>
|
@@ -37,15 +32,10 @@ dependencies:
|
|
37
32
|
version: 1.3.4
|
38
33
|
type: :development
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.3.4
|
35
|
+
version_requirements: *78640740
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: jeweler
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &78640430 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
41
|
- - ~>
|
@@ -53,15 +43,10 @@ dependencies:
|
|
53
43
|
version: 1.8.3
|
54
44
|
type: :development
|
55
45
|
prerelease: false
|
56
|
-
version_requirements:
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.8.3
|
46
|
+
version_requirements: *78640430
|
62
47
|
- !ruby/object:Gem::Dependency
|
63
48
|
name: simplecov
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirement: &78639890 !ruby/object:Gem::Requirement
|
65
50
|
none: false
|
66
51
|
requirements:
|
67
52
|
- - ! '>='
|
@@ -69,31 +54,21 @@ dependencies:
|
|
69
54
|
version: '0'
|
70
55
|
type: :development
|
71
56
|
prerelease: false
|
72
|
-
version_requirements:
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
57
|
+
version_requirements: *78639890
|
78
58
|
- !ruby/object:Gem::Dependency
|
79
59
|
name: builtinextension
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirement: &78639610 !ruby/object:Gem::Requirement
|
81
61
|
none: false
|
82
62
|
requirements:
|
83
63
|
- - ! '>='
|
84
64
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.
|
65
|
+
version: 0.1.0
|
86
66
|
type: :development
|
87
67
|
prerelease: false
|
88
|
-
version_requirements:
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 0.0.0
|
68
|
+
version_requirements: *78639610
|
94
69
|
- !ruby/object:Gem::Dependency
|
95
70
|
name: weightedpicker
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirement: &78639330 !ruby/object:Gem::Requirement
|
97
72
|
none: false
|
98
73
|
requirements:
|
99
74
|
- - ! '>='
|
@@ -101,12 +76,7 @@ dependencies:
|
|
101
76
|
version: 0.1.0
|
102
77
|
type: :development
|
103
78
|
prerelease: false
|
104
|
-
version_requirements:
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 0.1.0
|
79
|
+
version_requirements: *78639330
|
110
80
|
description: This gem privide framework for quiz game. This gem can be used for spaced
|
111
81
|
repetition study. The more frequently mistaken problems are given more frequently.
|
112
82
|
email: ippei94da@gmail.com
|
@@ -132,7 +102,6 @@ files:
|
|
132
102
|
- example/hyakuninIsshuShort.yaml
|
133
103
|
- lib/quizgame.rb
|
134
104
|
- lib/quizgame/problem.rb
|
135
|
-
- lib/quizgame/quizgame.rb
|
136
105
|
- quizgame.gemspec
|
137
106
|
- test/helper.rb
|
138
107
|
- test/test_problem.rb
|
@@ -152,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
121
|
version: '0'
|
153
122
|
segments:
|
154
123
|
- 0
|
155
|
-
hash: -
|
124
|
+
hash: -638697139
|
156
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
126
|
none: false
|
158
127
|
requirements:
|
@@ -161,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
130
|
version: '0'
|
162
131
|
requirements: []
|
163
132
|
rubyforge_project:
|
164
|
-
rubygems_version: 1.8.
|
133
|
+
rubygems_version: 1.8.11
|
165
134
|
signing_key:
|
166
135
|
specification_version: 3
|
167
136
|
summary: Framework for game with quiz format.
|
data/lib/quizgame/quizgame.rb
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
# coding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
gem "builtinextension"
|
6
|
-
require "string_color.rb"
|
7
|
-
require "string_mismatch.rb"
|
8
|
-
|
9
|
-
gem "weightedpicker"
|
10
|
-
require "weightedpicker.rb"
|
11
|
-
|
12
|
-
require "quizgame/problem.rb"
|
13
|
-
require "yaml"
|
14
|
-
|
15
|
-
include Math
|
16
|
-
|
17
|
-
# クイズゲームを管理・実行するクラス。
|
18
|
-
class QuizGame
|
19
|
-
QUIT_STR = "q"
|
20
|
-
#NEXT_STR = ""
|
21
|
-
NUM_EMPTY_LINE = 8
|
22
|
-
#MINIMUM_INTERVAL = 10 #同じ問題を再出題する最短の interval
|
23
|
-
|
24
|
-
class QuizGame::NoQuizError < Exception; end
|
25
|
-
|
26
|
-
# クイズデータを読み込む。
|
27
|
-
def initialize(requirement, problems, picker_file)
|
28
|
-
@requirement = requirement
|
29
|
-
@problems = problems
|
30
|
-
@weight_file = picker_file
|
31
|
-
end
|
32
|
-
|
33
|
-
# 条件を満たすまでクイズを実行。
|
34
|
-
# norma は終了条件の数
|
35
|
-
def run(norma)
|
36
|
-
begin
|
37
|
-
picker = WeightedPicker.load_file @weight_file
|
38
|
-
picker.merge @problems.keys
|
39
|
-
rescue WeightedPicker::InvalidWeightError
|
40
|
-
puts "Error!"
|
41
|
-
puts "#{@weight_file} contains float weight. Use integers as weights."
|
42
|
-
exit
|
43
|
-
rescue Errno::ENOENT
|
44
|
-
#puts "TEST"
|
45
|
-
picker = WeightedPicker.new({})
|
46
|
-
picker.merge @problems.keys
|
47
|
-
end
|
48
|
-
|
49
|
-
correct_count = 0
|
50
|
-
problem_count = 0
|
51
|
-
show_statement(norma)
|
52
|
-
puts "Requirement: ", @requirement
|
53
|
-
|
54
|
-
start_time = Time.new
|
55
|
-
|
56
|
-
while (problem_count < norma )
|
57
|
-
id = picker.pick
|
58
|
-
problem = @problems[id]
|
59
|
-
|
60
|
-
puts "-"*60
|
61
|
-
print "[Q.#{problem_count+1}, #{id}] "
|
62
|
-
problem.exhibit_question
|
63
|
-
|
64
|
-
input_str = user_input
|
65
|
-
(puts "-- Interrupted --"; break) if (input_str == QUIT_STR)
|
66
|
-
#(puts "-- Next --"; next) if (input_str == NEXT_STR)
|
67
|
-
|
68
|
-
problem_count += 1
|
69
|
-
if problem.correct?(input_str)
|
70
|
-
correct_count += 1
|
71
|
-
picker.lighten(id)
|
72
|
-
else
|
73
|
-
picker.weigh(id)
|
74
|
-
end
|
75
|
-
|
76
|
-
puts show_result(problem, input_str)
|
77
|
-
puts problem.show_supplement
|
78
|
-
#pp correct_count
|
79
|
-
#pp problem_count
|
80
|
-
#pp @norma
|
81
|
-
printf( "[%d correct / %d problems / %d norma]\n",
|
82
|
-
correct_count, problem_count, norma)
|
83
|
-
end
|
84
|
-
|
85
|
-
File.open(@weight_file, "w"){|io| picker.dump(io) }
|
86
|
-
|
87
|
-
puts "="*60
|
88
|
-
sleep(0.35) #Visual effect. A little stop before showing results.
|
89
|
-
if (correct_count == norma)
|
90
|
-
show_great
|
91
|
-
end
|
92
|
-
|
93
|
-
printf("result: [%d correct / %d problems]",
|
94
|
-
correct_count, problem_count)
|
95
|
-
|
96
|
-
begin
|
97
|
-
printf(" %2d\%\n", (correct_count.to_f/ problem_count*100).to_i)
|
98
|
-
rescue FloatDomainError
|
99
|
-
puts " No problem is answered."
|
100
|
-
end
|
101
|
-
|
102
|
-
print "Time: ", Time.now - start_time, "\n"
|
103
|
-
end
|
104
|
-
|
105
|
-
private
|
106
|
-
|
107
|
-
#ゲーム開始前に情報を提示。
|
108
|
-
def show_statement(norma, io = $stdout)
|
109
|
-
io.puts "#{QUIT_STR}[Enter] for immediately quit."
|
110
|
-
io.puts
|
111
|
-
io.puts "This program has #{@problems.size} problems."
|
112
|
-
io.print "Norma: " + norma.to_s.color(:green) + " "
|
113
|
-
io.puts "problems."
|
114
|
-
end
|
115
|
-
|
116
|
-
def user_input(input = STDIN, output = $stdout)
|
117
|
-
output.print "\n" * NUM_EMPTY_LINE
|
118
|
-
output.print "input: "
|
119
|
-
return input.gets.chomp!
|
120
|
-
end
|
121
|
-
|
122
|
-
#
|
123
|
-
def show_result(problem, str, io = $stdout)
|
124
|
-
if (problem.correct?(str) == false)
|
125
|
-
io.puts "×: ".color(:red) + problem.emphasize_wrong(str)
|
126
|
-
end
|
127
|
-
io.puts "○: #{problem.answer}"
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
def show_great
|
132
|
-
print "\n"
|
133
|
-
great = Array.new
|
134
|
-
puts "■■■■■□■■■■■□■■■■■□■■■■■□■■■■■□■□■".color(:red )
|
135
|
-
puts "■□□□□□■□□□■□■□□□□□■□□□■□□□■□□□■□■".color(:yellow)
|
136
|
-
puts "■□■■■□■■■■■□■■■■■□■■■■■□□□■□□□■□■".color(:green )
|
137
|
-
puts "■□□□■□■□□■□□■□□□□□■□□□■□□□■□□□□□□".color(:cyan )
|
138
|
-
puts "■■■■■□■□□□■□■■■■■□■□□□■□□□■□□□■□■".color(:blue )
|
139
|
-
puts
|
140
|
-
puts "All answers are correct!"
|
141
|
-
puts
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|