ai_games-four_in_a_row 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 112f56e83bbfff9998c24bdcc5fc2bfb872389a4
4
+ data.tar.gz: e939277afc1ec3927f1fc41398e93f17ba120264
5
+ SHA512:
6
+ metadata.gz: 46c9df8a8797ccd1c93a5a77946adb80241739ec96f995d67dee8f057c672b9bfcd618f961e204846709c514eb7e6a39a0f09e399e6361707fa06936c512473b
7
+ data.tar.gz: c7e60410280b9e3d42ddd2f3a1fa967dc03d5b170f57a3c4b835723eb8c81bf5960b87804bc2b6168c128994adad71d7371a59f88ee31d226842f87952b88477
data/.gitignore ADDED
@@ -0,0 +1,147 @@
1
+ # Created by https://www.gitignore.io/api/linux,osx,windows,ruby,rubymine
2
+
3
+ ### Linux ###
4
+ *~
5
+
6
+ # KDE directory preferences
7
+ .directory
8
+
9
+ # Linux trash folder which might appear on any partition or disk
10
+ .Trash-*
11
+
12
+
13
+ ### OSX ###
14
+ .DS_Store
15
+ .AppleDouble
16
+ .LSOverride
17
+
18
+ # Icon must end with two \r
19
+ Icon
20
+
21
+
22
+ # Thumbnails
23
+ ._*
24
+
25
+ # Files that might appear in the root of a volume
26
+ .DocumentRevisions-V100
27
+ .fseventsd
28
+ .Spotlight-V100
29
+ .TemporaryItems
30
+ .Trashes
31
+ .VolumeIcon.icns
32
+
33
+ # Directories potentially created on remote AFP share
34
+ .AppleDB
35
+ .AppleDesktop
36
+ Network Trash Folder
37
+ Temporary Items
38
+ .apdisk
39
+
40
+
41
+ ### Windows ###
42
+ # Windows image file caches
43
+ Thumbs.db
44
+ ehthumbs.db
45
+
46
+ # Folder config file
47
+ Desktop.ini
48
+
49
+ # Recycle Bin used on file shares
50
+ $RECYCLE.BIN/
51
+
52
+ # Windows Installer files
53
+ *.cab
54
+ *.msi
55
+ *.msm
56
+ *.msp
57
+
58
+ # Windows shortcuts
59
+ *.lnk
60
+
61
+
62
+ ### Ruby ###
63
+ *.gem
64
+ *.rbc
65
+ /.config
66
+ /coverage/
67
+ /InstalledFiles
68
+ /pkg/
69
+ /spec/reports/
70
+ /spec/examples.txt
71
+ /test/tmp/
72
+ /test/version_tmp/
73
+ /tmp/
74
+
75
+ ## Specific to RubyMotion:
76
+ .dat*
77
+ .repl_history
78
+ build/
79
+
80
+ ## Documentation cache and generated files:
81
+ /.yardoc/
82
+ /_yardoc/
83
+ /doc/
84
+ /rdoc/
85
+
86
+ ## Environment normalisation:
87
+ /.bundle/
88
+ /vendor/bundle
89
+ /lib/bundler/man/
90
+
91
+ # for a library or gem, you might want to ignore these files since the code is
92
+ # intended to run in multiple environments; otherwise, check them in:
93
+ Gemfile.lock
94
+ .ruby-version
95
+ .ruby-gemset
96
+
97
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
98
+ .rvmrc
99
+
100
+
101
+ ### RubyMine ###
102
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
103
+
104
+ *.iml
105
+
106
+ ## Directory-based project format:
107
+ .idea/
108
+ # if you remove the above rule, at least ignore the following:
109
+
110
+ # User-specific stuff:
111
+ # .idea/workspace.xml
112
+ # .idea/tasks.xml
113
+ # .idea/dictionaries
114
+
115
+ # Sensitive or high-churn files:
116
+ # .idea/dataSources.ids
117
+ # .idea/dataSources.xml
118
+ # .idea/sqlDataSources.xml
119
+ # .idea/dynamic.xml
120
+ # .idea/uiDesigner.xml
121
+
122
+ # Gradle:
123
+ # .idea/gradle.xml
124
+ # .idea/libraries
125
+
126
+ # Mongo Explorer plugin:
127
+ # .idea/mongoSettings.xml
128
+
129
+ ## File-based project format:
130
+ *.ipr
131
+ *.iws
132
+
133
+ ## Plugin-specific files:
134
+
135
+ # IntelliJ
136
+ /out/
137
+
138
+ # mpeltonen/sbt-idea plugin
139
+ .idea_modules/
140
+
141
+ # JIRA plugin
142
+ atlassian-ide-plugin.xml
143
+
144
+ # Crashlytics plugin (for Android Studio and IntelliJ)
145
+ com_crashlytics_export_strings.xml
146
+ crashlytics.properties
147
+ crashlytics-build.properties
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/**/*'
4
+
5
+ Style/Documentation:
6
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,27 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people
4
+ who contribute through reporting issues, posting feature requests, updating
5
+ documentation, submitting pull requests or patches, and other activities.
6
+
7
+ We are committed to making participation in this project a harassment-free
8
+ experience for everyone, regardless of level of experience, gender, gender
9
+ identity and expression, sexual orientation, disability, personal appearance,
10
+ body size, race, ethnicity, age, or religion.
11
+
12
+ Examples of unacceptable behavior by participants include the use of sexual
13
+ language or imagery, derogatory comments or personal attacks, trolling, public
14
+ or private harassment, insults, or other unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject
17
+ comments, commits, code, wiki edits, issues, and other contributions that are
18
+ not aligned to this Code of Conduct. Project maintainers who do not follow the
19
+ Code of Conduct may be removed from the project team.
20
+
21
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
22
+ reported by opening an issue or contacting one or more of the project
23
+ maintainers.
24
+
25
+ This Code of Conduct is adapted from the
26
+ [Contributor Covenant](http://contributor-covenant.org), version 1.0.0,
27
+ available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ai_games-four_in_a_row.gemspec
4
+ gemspec
5
+
6
+ gem 'ai_games-logger', github: 'jdno/ai_games-logger', branch: 'develop'
7
+ gem 'ai_games-parser', github: 'jdno/ai_games-parser', branch: 'develop'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jan David Nose
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # AIGames::FourInARow
2
+
3
+ Library and starter bot for [The AI Games'] new competition
4
+ [Four in a Row](http://theaigames.com/competitions/four-in-a-row/).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ai_games-four_in_a_row'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install ai_games-four_in_a_row
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
29
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
30
+ prompt that will allow you to experiment.
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at
35
+ https://github.com/jdno/ai_games-four_in_a_row. This project is intended to be a
36
+ safe, welcoming space for collaboration, and contributors are expected to adhere
37
+ to the [Contributor Covenant](contributor-covenant.org) code of conduct.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the
42
+ [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ai_games/four_in_a_row/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ai_games-four_in_a_row'
8
+ spec.version = AIGames::FourInARow::VERSION
9
+ spec.authors = ['Jan David Nose']
10
+ spec.email = ['jandavid@awesometechnology.de']
11
+
12
+ spec.summary = <<-EOF
13
+ Framework and starter bot for The AI Games' 'Four in a Row' competition"
14
+ EOF
15
+ spec.description = <<-EOF
16
+ This gem provides a framework that can be used to implement a bot for The
17
+ AI Games' competition 'Four in a Row'. It handles the communication with the
18
+ game engine, so that you can focus on your bot.
19
+ EOF
20
+ spec.homepage = 'https://github.com/jdno/ai_games-four_in_a_row'
21
+ spec.license = 'MIT'
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_runtime_dependency 'ai_games-logger'
31
+ spec.add_runtime_dependency 'ai_games-parser'
32
+
33
+ spec.add_development_dependency 'bundler', '~> 1.10'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'minitest'
36
+ spec.add_development_dependency 'rubocop'
37
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ai_games/four_in_a_row"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
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/four_in_a_row/version'
21
+
22
+ module AIGames
23
+ module FourInARow
24
+ # Your code goes here...
25
+ end
26
+ end
@@ -0,0 +1,55 @@
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/four_in_a_row/match'
21
+
22
+ module AIGames
23
+ module FourInARow
24
+ class Bot
25
+ # Time in milliseconds that the bot has in its time bank
26
+ attr_accessor :current_time_bank
27
+
28
+ # Maximum time in milliseconds that the bot can have in its time bank
29
+ attr_accessor :maximum_time_bank
30
+
31
+ # Time in milliseconds that is added to the bot's time bank each move
32
+ attr_accessor :time_per_move
33
+
34
+ # The match instance
35
+ attr_reader :match
36
+
37
+ # Initializes a new bot.
38
+ def initialize(match = nil)
39
+ @match = match || Match.instance
40
+ end
41
+
42
+ # Places a disk. This method MUST return a single integer value, denoting
43
+ # the column you want to drop a pin in. To customize your bot, overwrite
44
+ # this method with your own implementation.
45
+ def place_disc
46
+ rand(0..match.columns)
47
+ end
48
+
49
+ # Starts this bot.
50
+ def run
51
+ @match.parser.run
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,71 @@
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/four_in_a_row/bot'
21
+ require 'ai_games/four_in_a_row/parser'
22
+ require 'ai_games/four_in_a_row/playing_field'
23
+ require 'singleton'
24
+
25
+ module AIGames
26
+ module FourInARow
27
+ # This class maintains a state of the current match and provides access to
28
+ # the bots, the playing field and the parser. It implements the singleton
29
+ # pattern to ensure that only a single instance of the match state exists
30
+ # at any given time.
31
+ class Match
32
+ # This class implements the singleton pattern to ensure that there is only
33
+ # a single instance passed around the application at any time. This is
34
+ # important due to the way information is shared between the parser and
35
+ # the bots.
36
+ include Singleton
37
+
38
+ # A hash mapping the ids to the bots, with bots[0] being nil and bots[1]
39
+ # and bots[2] containing the two players.
40
+ attr_reader :bots
41
+
42
+ # The player's bot
43
+ attr_reader :my_bot
44
+
45
+ # The enemy's bot
46
+ attr_reader :enemy_bot
47
+
48
+ # The current round
49
+ attr_accessor :round
50
+
51
+ # The instance of the parser
52
+ attr_reader :parser
53
+
54
+ # The instance of the playing field
55
+ attr_accessor :playing_field
56
+
57
+ # Initializes a new match instance. If a custom bot is given, it is used
58
+ # as the player's bot, else the default bot is used for both the player
59
+ # and the enemy.
60
+ def initialize(bot = nil)
61
+ @bots = {}
62
+ @bots[0] = nil
63
+ @my_bot = bot || Bot.new(self)
64
+ @enemy_bot = Bot.new(self)
65
+ @parser = Parser.new(self)
66
+ @round = 0
67
+ @playing_field = PlayingField.new(6, 7)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,156 @@
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
+ require 'ai_games/parser/abstract_parser'
22
+
23
+ module AIGames
24
+ module FourInARow
25
+ # The parser handles the communication with the game engine. It sets up the
26
+ # game using the information provided by the engine before the game starts,
27
+ # and updates the match when new information comes in.
28
+ class Parser < AIGames::Parser::AbstractParser
29
+ # The match instance
30
+ attr_reader :match
31
+
32
+ # Initializes the parser with the given match instance.
33
+ def initialize(match, options = nil)
34
+ super(options)
35
+ @match = match
36
+ end
37
+
38
+ # For the methods parsing the input, a few cops have been disabled.
39
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/LineLength
40
+
41
+ # Parses the game engine's commands. This overwrites DefaultParser.parse
42
+ # with the specific instructions needed for the "Four In A Row"
43
+ # competition.
44
+ def parse(command_array)
45
+ case command_array[0]
46
+ when 'action'
47
+ parse_action command_array[2].to_i
48
+ when 'update'
49
+ parse_update command_array[2..-1]
50
+ when 'settings'
51
+ parse_settings command_array[1..-1]
52
+ else
53
+ Logger.warn('Parser.parse : Unknown command ' \
54
+ "'#{command_array.join ' '}'")
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ # Parses all commands starting with "action". Right now, this is true only
61
+ # for a single command. The response to this command is the move the bot
62
+ # wants to make.
63
+ def parse_action(time_bank)
64
+ @match.my_bot.current_time_bank = time_bank
65
+ "place_disc #{@match.my_bot.place_disk}"
66
+ end
67
+
68
+ # Parses all commands starting with "update". This is either the number of
69
+ # round, or an update to the playing field.
70
+ def parse_update(updates_array)
71
+ case updates_array[0]
72
+ when 'round'
73
+ match.round = updates_array[1].to_i
74
+ when 'field'
75
+ parse_field updates_array[1]
76
+ else
77
+ Logger.warn("Parser.parse_updates : Unknown command 'update game" \
78
+ "#{updates_array.join ' '}'")
79
+ end
80
+ end
81
+
82
+ # Parses all commands starting with "settings". These are issued once when
83
+ # the game starts, and configure the game.
84
+ def parse_settings(settings_array)
85
+ case settings_array[0]
86
+ when 'timebank'
87
+ parse_time_bank settings_array[1].to_i
88
+ when 'time_per_move'
89
+ parse_time_per_move settings_array[1].to_i
90
+ when 'player_names'
91
+ # Names are irrelevant, do nothing.
92
+ when 'your_bot'
93
+ # Names are irrelevant, do nothing.
94
+ when 'your_botid'
95
+ parse_bot_id settings_array[1].to_i
96
+ when 'field_columns'
97
+ parse_columns settings_array[1].to_i
98
+ when 'field_rows'
99
+ parse_rows settings_array[1].to_i
100
+ else
101
+ Logger.warn("Parser.parse_settings : Unknown command 'settings " \
102
+ "#{settings_array.join ' '}'")
103
+ end
104
+ end
105
+
106
+ # rubocop:enable all
107
+
108
+ # Parses the updated playing field. The only argument is the new playing
109
+ # field encoded as a string.
110
+ def parse_field(field_string)
111
+ i = 0
112
+ field_string.split(';').each do |r|
113
+ j = 0
114
+ r.split(',').each do |c|
115
+ match.playing_field[i][j] = match.bots[c.to_i]
116
+ j += 1
117
+ end
118
+ i += 1
119
+ end
120
+ end
121
+
122
+ # Sets up the bot ids in the beginning of the game.
123
+ def parse_bot_id(id)
124
+ match.bots[id] = match.my_bot
125
+
126
+ if id == 1
127
+ match.bots[2] = match.enemy_bot
128
+ else
129
+ match.bots[1] = match.enemy_bot
130
+ end
131
+ end
132
+
133
+ # Sets the playing field's number of columns
134
+ def parse_columns(columns)
135
+ match.playing_field.columns = columns
136
+ end
137
+
138
+ # Sets the playing field's number of rows
139
+ def parse_rows(rows)
140
+ match.playing_field.rows = rows
141
+ end
142
+
143
+ # Sets the maximum time bank the bots can use
144
+ def parse_time_bank(time_bank)
145
+ match.my_bot.maximum_time_bank = time_bank
146
+ match.enemy_bot.maximum_time_bank = time_bank
147
+ end
148
+
149
+ # Sets the time that is added with each move
150
+ def parse_time_per_move(time)
151
+ match.my_bot.time_per_move = time
152
+ match.enemy_bot.time_per_move = time
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,68 @@
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
+ module AIGames
21
+ module FourInARow
22
+ # This class represents the playing field of the game. It has a given number
23
+ # of columns and rows, and each field can either be empty or filled. If a
24
+ # field is filled, the name of the player whose chip fills the field is
25
+ # stored in it.
26
+ class PlayingField
27
+ # The number of columns of the playing field
28
+ attr_reader :columns
29
+
30
+ # The number of rows of the playing field
31
+ attr_reader :rows
32
+
33
+ # A two-dimensional array containing all the fields of the playing field
34
+ attr_reader :fields
35
+
36
+ # Initialize the playing field with the given number of rows and columns.
37
+ def initialize(rows = 0, columns = 0)
38
+ resize_field rows, columns
39
+ end
40
+
41
+ # Shortcut to the field elements, using the playing field itself like the
42
+ # underlying array structure.
43
+ def [](index)
44
+ @fields[index]
45
+ end
46
+
47
+ # Sets number of rows. If the new number of rows is greater than the
48
+ # current number of rows, the array gets resized.
49
+ def rows=(rows)
50
+ resize_field rows, @columns
51
+ end
52
+
53
+ # Sets the number of columns. If the new number of columns is greater than
54
+ # the current number of columns, the array gets resized.
55
+ def columns=(columns)
56
+ resize_field @rows, columns
57
+ end
58
+
59
+ private
60
+
61
+ def resize_field(rows, columns)
62
+ @columns = columns
63
+ @rows = rows
64
+ @fields = Array.new(rows) { Array.new(columns) { nil } }
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
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
+ module AIGames
21
+ module FourInARow
22
+ VERSION = '0.1.0'
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ai_games-four_in_a_row
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan David Nose
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ai_games-logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ai_games-parser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |
98
+ This gem provides a framework that can be used to implement a bot for The
99
+ AI Games' competition 'Four in a Row'. It handles the communication with the
100
+ game engine, so that you can focus on your bot.
101
+ email:
102
+ - jandavid@awesometechnology.de
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - ".rubocop.yml"
109
+ - ".travis.yml"
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - ai_games-four_in_a_row.gemspec
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/ai_games/four_in_a_row.rb
119
+ - lib/ai_games/four_in_a_row/bot.rb
120
+ - lib/ai_games/four_in_a_row/match.rb
121
+ - lib/ai_games/four_in_a_row/parser.rb
122
+ - lib/ai_games/four_in_a_row/playing_field.rb
123
+ - lib/ai_games/four_in_a_row/version.rb
124
+ homepage: https://github.com/jdno/ai_games-four_in_a_row
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.4.6
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Framework and starter bot for The AI Games' 'Four in a Row' competition"
148
+ test_files: []