ai_games-parser 0.2.1 → 0.3.0

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: d5b41a1a1e251dcd3c7658f53b2bfd67fb7bb7b6
4
- data.tar.gz: 98a93a6bc74c86b847ee4ec2a4b3494d8f33cfa4
3
+ metadata.gz: 104e313efe3bb5652763cac019387c01c317ea19
4
+ data.tar.gz: 45d018cea9e91843c1a01d79cf61d19276de1e7b
5
5
  SHA512:
6
- metadata.gz: 438b3eb049af5df64296331270d331ecfcf9f1a8e210f9a80c86ea84a602aae4a5acd31b56ad9e3cc7327b7473ec972d4249918d309c3a1efb5897328517478a
7
- data.tar.gz: 07a2bd52130a50a9432cc632871b516c06ce899ebd4e6ac81c12d553b4a815efef7be4b9f47008326aa08fa6914aa6d9419007e576be85c409b5c759a8c62a06
6
+ metadata.gz: 093861ab9761b09a16508d6000df2cab157ebce6d2320e4f3f09fa3d86e2eba09ecbc1499687a08887a462006a2a3dd9704ffb07620721b886d2011f74165a4e
7
+ data.tar.gz: ac727de7853114168711c4422872ae6f20175de53d842b4dcc2daa4f74784d89bed2a3b552787be303382c2b13f832a82291eb8c17a62dc82a667452687b14df
data/.codeclimate.yml ADDED
@@ -0,0 +1,16 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby
8
+ fixme:
9
+ enabled: true
10
+ rubocop:
11
+ enabled: true
12
+ ratings:
13
+ paths:
14
+ - "**.rb"
15
+ exclude_paths:
16
+ - bin/
data/.rubocop.yml CHANGED
@@ -1,6 +1,3 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - 'bin/**/*'
4
-
5
- Style/Documentation:
6
- Enabled: false
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
4
- before_install: gem install bundler -v 1.10.6
3
+ - 2.3.0
4
+ before_install: gem install bundler
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ai_games-parser.gemspec
4
4
  gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Jan David Nose
3
+ Copyright (c) 2016 Jan David Nose
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # AIGames::Parser
2
2
 
3
+ [![Build Status](https://travis-ci.org/jdno/ai_games-parser.svg?branch=develop)](https://travis-ci.org/jdno/ai_games-parser)
4
+ [![Code Climate](https://codeclimate.com/github/jdno/ai_games-parser/badges/gpa.svg)](https://codeclimate.com/github/jdno/ai_games-parser)
5
+ [![Test Coverage](https://codeclimate.com/github/jdno/ai_games-parser/badges/coverage.svg)](https://codeclimate.com/github/jdno/ai_games-parser/coverage)
6
+
3
7
  This gem provides a parser that can be used to communicate with the game engine
4
8
  in The AI Games' competitions. By extending it, the parser can be customized to
5
9
  work in any competition.
@@ -22,7 +26,9 @@ Or install it yourself as:
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ The gem provides an abstract parser in `AIGames::Parser`. Extend this class, and
30
+ overwrite the method `parse(command_array)` to customize your parser for the
31
+ specific challenge.
26
32
 
27
33
  ## Development
28
34
 
@@ -39,5 +45,22 @@ the [Contributor Covenant](contributor-covenant.org) code of conduct.
39
45
 
40
46
  ## License
41
47
 
42
- The gem is available as open source under the terms of the
43
- [MIT License](http://opensource.org/licenses/MIT).
48
+ Copyright (c) 2016 [Jan David Nose](https://github.com)
49
+
50
+ Permission is hereby granted, free of charge, to any person obtaining a copy
51
+ of this software and associated documentation files (the "Software"), to deal
52
+ in the Software without restriction, including without limitation the rights
53
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
54
+ copies of the Software, and to permit persons to whom the Software is
55
+ furnished to do so, subject to the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be included in
58
+ all copies or substantial portions of the Software.
59
+
60
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
61
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
62
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
63
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
64
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
65
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
66
+ THE SOFTWARE.
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ai_games/parser/version'
4
+ require 'ai_games/parser'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'ai_games-parser'
@@ -1,7 +1,83 @@
1
- require 'ai_games/parser/version'
2
-
3
1
  module AIGames
4
- module Parser
5
- # Your code goes here...
2
+ # This class provides an abstract parser that can be extended to implement
3
+ # the logic that is required for a specific competition. It provides methods
4
+ # to communicate with the game engine, but does NOT contain any logic how to
5
+ # parse the engine's commands. This is totally up to the implementations of
6
+ # this class.
7
+ class Parser
8
+ VERSION = '0.3.0'
9
+
10
+ # Initializes the parser. Pass in options using a hash structure.
11
+ def initialize(options = nil)
12
+ initialize_streams options if options
13
+ end
14
+
15
+ # Starts the main loop. This loop runs until the game engine closes the
16
+ # console line. During the loop, the parser reads from the game engine,
17
+ # sanitizes the input a little bit, and then passes it to a method that
18
+ # needs to be overwritten by parsers extending this interface.
19
+ def run
20
+ AIGames::Logger.info 'Parser.run : Starting loop'
21
+
22
+ loop do
23
+ command = read_from_engine
24
+ break if command.nil?
25
+
26
+ command.strip!
27
+ next if command.length == 0
28
+
29
+ response = parse split_line command
30
+ write_to_engine response unless response.nil? || response.length < 1
31
+ end
32
+
33
+ AIGames::Logger.info 'Parser.run : Stopping loop'
34
+ end
35
+
36
+ # Parses the given command array. This method MUST return a valid response
37
+ # string that can be send to the engine.
38
+ # rubocop:disable Lint/UnusedMethodArgument
39
+ def parse(command_array)
40
+ fail 'Method must be overwritten'
41
+ end
42
+ # rubocop:enable Lint/UnusedMethodArgument
43
+
44
+ private
45
+
46
+ # Initializes the input and output streams that the parser uses. The
47
+ # expected format for the options is a hash with the keys `:input` and
48
+ # `:output`. Use this to mock `STDIN` and `STDOUT` for tests.
49
+ def initialize_streams(options)
50
+ @input = options[:input] if options.key? :input
51
+ @output = options[:output] if options.key? :output
52
+ end
53
+
54
+ # Returns the input stream. If no stream has been configured, $stdin is
55
+ # returned.
56
+ def input
57
+ @input ||= $stdin
58
+ end
59
+
60
+ # Returns the output stream. If no stream has been configured, $stdout is
61
+ # returned.
62
+ def output
63
+ @output ||= $stdout
64
+ end
65
+
66
+ # Reads from the input stream.
67
+ def read_from_engine
68
+ input.gets
69
+ end
70
+
71
+ # Writes to the output stream.
72
+ def write_to_engine(string)
73
+ output.puts string
74
+ output.flush
75
+ end
76
+
77
+ # Formats a command line for further processing. The input is split at the
78
+ # whitespace character, and all its parts are converted to downcase.
79
+ def split_line(line)
80
+ line.split(' ').map(&:downcase)
81
+ end
6
82
  end
7
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ai_games-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan David Nose
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ai_games-logger
@@ -90,6 +90,7 @@ executables: []
90
90
  extensions: []
91
91
  extra_rdoc_files: []
92
92
  files:
93
+ - ".codeclimate.yml"
93
94
  - ".gitignore"
94
95
  - ".rubocop.yml"
95
96
  - ".travis.yml"
@@ -102,8 +103,6 @@ files:
102
103
  - bin/console
103
104
  - bin/setup
104
105
  - lib/ai_games/parser.rb
105
- - lib/ai_games/parser/abstract_parser.rb
106
- - lib/ai_games/parser/version.rb
107
106
  homepage: https://github.com/jdno/ai_games-parser
108
107
  licenses:
109
108
  - MIT
@@ -124,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
123
  version: '0'
125
124
  requirements: []
126
125
  rubyforge_project:
127
- rubygems_version: 2.4.6
126
+ rubygems_version: 2.5.1
128
127
  signing_key:
129
128
  specification_version: 4
130
129
  summary: Skeleton for a parser for The AI Games' competitions
@@ -1,104 +0,0 @@
1
- # Copyright (c) 2015 Jan David Nose
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
- require 'ai_games/logger'
21
-
22
- module AIGames
23
- module Parser
24
- # This class provides an abstract parser that can be extended to implement
25
- # the logic that is required for a specific competition. It provides methods
26
- # to communicate with the game engine, but does NOT contain any logic how to
27
- # parse the engine's commands. This is totally up to the implementations of
28
- # this class.
29
- class AbstractParser
30
- # Initializes the parser. Pass in options using a hash structure.
31
- def initialize(options = nil)
32
- initialize_streams options if options
33
- end
34
-
35
- # Starts the main loop. This loop runs until the game engine closes the
36
- # console line. During the loop, the parser reads from the game engine,
37
- # sanitizes the input a little bit, and then passes it to a method that
38
- # needs to be overwritten by parsers extending this interface.
39
- def run
40
- AIGames::Logger.info 'Parser.run : Starting loop'
41
-
42
- loop do
43
- command = read_from_engine
44
- break if command.nil?
45
-
46
- command.strip!
47
- next if command.length == 0
48
-
49
- response = parse split_line command
50
- write_to_engine response unless response.nil? || response.length < 1
51
- end
52
-
53
- AIGames::Logger.info 'Parser.run : Stopping loop'
54
- end
55
-
56
- # Parses the given command array. This method MUST return a valid response
57
- # string that can be send to the engine.
58
- # rubocop:disable Lint/UnusedMethodArgument
59
- def parse(command_array)
60
- fail 'Method must be overwritten'
61
- end
62
- # rubocop:enable Lint/UnusedMethodArgument
63
-
64
- private
65
-
66
- # Initializes the input and output streams that the parser uses. The
67
- # expected format for the options is a hash with the keys `:input` and
68
- # `:output`. Use this to mock `STDIN` and `STDOUT` for tests.
69
- def initialize_streams(options)
70
- @input = options[:input] if options.key? :input
71
- @output = options[:output] if options.key? :output
72
- end
73
-
74
- # Returns the input stream. If no stream has been configured, $stdin is
75
- # returned.
76
- def input
77
- @input ||= $stdin
78
- end
79
-
80
- # Returns the output stream. If no stream has been configured, $stdout is
81
- # returned.
82
- def output
83
- @output ||= $stdout
84
- end
85
-
86
- # Reads from the input stream.
87
- def read_from_engine
88
- input.gets
89
- end
90
-
91
- # Writes to the output stream.
92
- def write_to_engine(string)
93
- output.puts string
94
- output.flush
95
- end
96
-
97
- # Formats a command line for further processing. The input is split at the
98
- # whitespace character, and all its parts are converted to downcase.
99
- def split_line(line)
100
- line.split(' ').map(&:downcase)
101
- end
102
- end
103
- end
104
- end
@@ -1,5 +0,0 @@
1
- module AIGames
2
- module Parser
3
- VERSION = '0.2.1'
4
- end
5
- end