neuro_gammon 0.7.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.
@@ -0,0 +1 @@
1
+ pkg/
@@ -0,0 +1,7 @@
1
+ \.orig$
2
+ \.orig\..*$
3
+ \.chg\..*$
4
+ \.rej$
5
+ \.player$
6
+ nbproject/*
7
+ pkg/*
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <loadpath>
3
+ <pathentry path="" type="src"/>
4
+ <pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con"/>
5
+ <pathentry path="GEM_LIB/jeweler-1.4.0/lib" type="var"/>
6
+ </loadpath>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>neuro_gammon</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.rubypeople.rdt.core.rubybuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ <buildCommand>
14
+ <name>com.aptana.ide.core.unifiedBuilder</name>
15
+ <arguments>
16
+ </arguments>
17
+ </buildCommand>
18
+ </buildSpec>
19
+ <natures>
20
+ <nature>com.aptana.ide.project.nature.web</nature>
21
+ <nature>org.rubypeople.rdt.core.rubynature</nature>
22
+ <nature>org.radrails.rails.core.railsnature</nature>
23
+ </natures>
24
+ </projectDescription>
data/README ADDED
@@ -0,0 +1,3 @@
1
+ == NeuralGammon
2
+
3
+ You should document your project here.
@@ -0,0 +1,37 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+
6
+
7
+ require 'rake'
8
+ require 'rake/testtask'
9
+ require 'rake/rdoctask'
10
+
11
+ gem 'jeweler'
12
+
13
+ task :default => [:test]
14
+
15
+ begin
16
+ require 'jeweler'
17
+ Jeweler::Tasks.new do |gemspec|
18
+ gemspec.name = "neuro_gammon"
19
+ gemspec.summary = "Neural Net Backgammon utility library - just a bit of messing about - nothing serious."
20
+ gemspec.email = "sowen@stuzart.org"
21
+ gemspec.authors = ["Stu"]
22
+ gemspec.add_dependency("uuidtools", ">= 2.1.1")
23
+ gemspec.add_dependency("ruby-fann", ">= 1.1.3")
24
+ gemspec.extra_rdoc_files = ["README"]
25
+ end
26
+ rescue LoadError
27
+ puts "Jeweler not available. Install it with: gem install jeweler"
28
+ end
29
+
30
+ task:test do
31
+ Rake::TestTask.new do |t|
32
+ t.libs << "test"
33
+ t.test_files = FileList['test/test*.rb']
34
+ t.verbose = true
35
+ end
36
+
37
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.7.0
@@ -0,0 +1,34 @@
1
+ FANN_FLO_2.1
2
+ num_layers=3
3
+ learning_rate=0.400000
4
+ connection_rate=1.000000
5
+ network_type=0
6
+ learning_momentum=0.000000
7
+ training_algorithm=2
8
+ train_error_function=1
9
+ train_stop_function=0
10
+ cascade_output_change_fraction=0.010000
11
+ quickprop_decay=-0.000100
12
+ quickprop_mu=1.750000
13
+ rprop_increase_factor=1.200000
14
+ rprop_decrease_factor=0.500000
15
+ rprop_delta_min=0.000000
16
+ rprop_delta_max=50.000000
17
+ rprop_delta_zero=0.100000
18
+ cascade_output_stagnation_epochs=12
19
+ cascade_candidate_change_fraction=0.010000
20
+ cascade_candidate_stagnation_epochs=12
21
+ cascade_max_out_epochs=150
22
+ cascade_max_cand_epochs=150
23
+ cascade_num_candidate_groups=2
24
+ bit_fail_limit=3.49999999999999977796e-01
25
+ cascade_candidate_limit=1.00000000000000000000e+03
26
+ cascade_weight_multiplier=4.00000000000000022204e-01
27
+ cascade_activation_functions_count=10
28
+ cascade_activation_functions=3 5 7 8 10 11 14 15 16 17
29
+ cascade_activation_steepnesses_count=4
30
+ cascade_activation_steepnesses=2.50000000000000000000e-01 5.00000000000000000000e-01 7.50000000000000000000e-01 1.00000000000000000000e+00
31
+ layer_sizes=27 31 5
32
+ scale_included=0
33
+ neurons (num_inputs, activation_function, activation_steepness)=(0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (27, 4, 5.00000000000000000000e-01) (0, 0, 0.00000000000000000000e+00) (31, 4, 5.00000000000000000000e-01) (31, 4, 5.00000000000000000000e-01) (31, 4, 5.00000000000000000000e-01) (31, 4, 5.00000000000000000000e-01) (0, 0, 0.00000000000000000000e+00)
34
+ connections (connected_to_neuron, weight)=(0, -5.01198954880237579346e-02) (1, -8.75940322875976562500e-02) (2, -3.16383615136146545410e-02) (3, 7.86770060658454895020e-02) (4, -5.56235387921333312988e-02) (5, 5.92326000332832336426e-02) (6, -3.33078950643539428711e-03) (7, 2.94327810406684875488e-02) (8, -5.86407184600830078125e-02) (9, 5.13364374637603759766e-03) (10, -6.32415562868118286133e-02) (11, 1.05978846549987792969e-02) (12, 7.36845657229423522949e-02) (13, -7.37894922494888305664e-02) (14, 9.11426022648811340332e-02) (15, -8.72141271829605102539e-02) (16, -2.78530940413475036621e-02) (17, -3.70922088623046875000e-02) (18, 3.06176319718360900879e-02) (19, 8.22121128439903259277e-02) (20, -6.54989406466484069824e-02) (21, 1.21479257941246032715e-02) (22, -6.25194534659385681152e-02) (23, -2.24204361438751220703e-03) (24, -2.77265831828117370605e-02) (25, -6.67275488376617431641e-02) (26, -1.90588980913162231445e-02) (0, -4.68869023025035858154e-02) (1, -1.16590186953544616699e-02) (2, -1.78016498684883117676e-02) (3, 7.53219053149223327637e-02) (4, 3.82210835814476013184e-02) (5, -5.39568066596984863281e-03) (6, -5.63164614140987396240e-02) (7, 1.68980956077575683594e-02) (8, 3.89807894825935363770e-02) (9, -9.70838516950607299805e-02) (10, -8.64327028393745422363e-02) (11, -3.15864458680152893066e-02) (12, -5.57245723903179168701e-02) (13, 1.87009423971176147461e-02) (14, 5.17199933528900146484e-03) (15, 5.48733249306678771973e-02) (16, -7.61450827121734619141e-03) (17, 3.13825085759162902832e-02) (18, 4.60159257054328918457e-02) (19, 5.17137348651885986328e-03) (20, -9.64705795049667358398e-02) (21, -9.10762846469879150391e-02) (22, -6.42110034823417663574e-02) (23, 8.57415273785591125488e-02) (24, -5.65752200782299041748e-02) (25, 4.79369238018989562988e-02) (26, -7.67779201269149780273e-02) (0, 4.11827340722084045410e-02) (1, -7.97896534204483032227e-02) (2, -4.35054786503314971924e-02) (3, -7.78761655092239379883e-02) (4, -2.66765579581260681152e-02) (5, 4.48355004191398620605e-02) (6, 4.32218611240386962891e-03) (7, -5.13546578586101531982e-02) (8, -1.69434100389480590820e-02) (9, 9.89265069365501403809e-02) (10, -7.67111033201217651367e-03) (11, 9.99546721577644348145e-02) (12, 3.79072949290275573730e-02) (13, -4.75496798753738403320e-03) (14, -8.64780247211456298828e-02) (15, -9.36791598796844482422e-02) (16, 3.95204648375511169434e-02) (17, 3.22229191660881042480e-02) (18, 1.14928483963012695312e-02) (19, -5.60621917247772216797e-03) (20, -7.53915831446647644043e-02) (21, -5.71246407926082611084e-02) (22, -5.95902912318706512451e-02) (23, 2.97797992825508117676e-02) (24, -5.35952262580394744873e-02) (25, -5.06665743887424468994e-02) (26, 6.55687823891639709473e-02) (0, -6.78536966443061828613e-02) (1, -7.24179297685623168945e-03) (2, 1.35057196021080017090e-02) (3, -4.46316190063953399658e-02) (4, -6.60590678453445434570e-02) (5, 3.37160602211952209473e-02) (6, 1.18629112839698791504e-02) (7, -4.39352281391620635986e-02) (8, -9.29604992270469665527e-02) (9, -4.33015935122966766357e-02) (10, 6.03869631886482238770e-02) (11, -4.43151555955410003662e-02) (12, 3.97549942135810852051e-02) (13, 5.93134686350822448730e-02) (14, 4.80137392878532409668e-02) (15, 3.97096797823905944824e-02) (16, -2.77924537658691406250e-03) (17, -5.67412339150905609131e-02) (18, 5.32316491007804870605e-02) (19, 3.54158878326416015625e-03) (20, 8.27792361378669738770e-02) (21, -1.45454332232475280762e-02) (22, -8.49655643105506896973e-02) (23, -2.28269845247268676758e-02) (24, 1.00629776716232299805e-02) (25, -4.20902073383331298828e-02) (26, 1.75827145576477050781e-02) (0, -6.01572282612323760986e-02) (1, 4.31456416845321655273e-03) (2, 6.69161453843116760254e-02) (3, -9.45884436368942260742e-02) (4, 3.64608839154243469238e-02) (5, -4.03256490826606750488e-02) (6, 1.89172774553298950195e-02) (7, 9.18292626738548278809e-02) (8, -6.38471543788909912109e-03) (9, -4.73666600883007049561e-02) (10, 3.69216501712799072266e-03) (11, 4.96800616383552551270e-02) (12, -4.03271615505218505859e-02) (13, 6.03905841708183288574e-02) (14, 1.00670233368873596191e-02) (15, 1.53576880693435668945e-02) (16, 1.45569443702697753906e-04) (17, -3.06195095181465148926e-02) (18, -3.66285815834999084473e-02) (19, -6.01447634398937225342e-02) (20, 6.66012391448020935059e-02) (21, 6.63018226623535156250e-03) (22, 9.30868908762931823730e-02) (23, -2.98571661114692687988e-02) (24, -1.05905905365943908691e-02) (25, -2.14585512876510620117e-02) (26, -1.48227363824844360352e-02) (0, 6.65824189782142639160e-02) (1, 8.86044427752494812012e-02) (2, 4.30870726704597473145e-02) (3, -1.58348530530929565430e-02) (4, -7.15527907013893127441e-02) (5, -5.25983683764934539795e-02) (6, -4.89187128841876983643e-02) (7, -6.61412328481674194336e-02) (8, 8.38625058531761169434e-02) (9, 1.07556432485580444336e-02) (10, 5.27760460972785949707e-02) (11, 7.56917670369148254395e-02) (12, -9.56290736794471740723e-02) (13, -9.45906192064285278320e-02) (14, -2.06160619854927062988e-02) (15, 5.40509894490242004395e-02) (16, -3.49177792668342590332e-02) (17, -6.02254904806613922119e-02) (18, -3.58819812536239624023e-02) (19, 8.04399028420448303223e-02) (20, 3.99200841784477233887e-02) (21, 3.34985032677650451660e-02) (22, -5.61886765062808990479e-02) (23, 7.97753259539604187012e-02) (24, 9.97409224510192871094e-05) (25, 5.04415109753608703613e-02) (26, 7.28622004389762878418e-02) (0, 7.02425912022590637207e-02) (1, -6.01490847766399383545e-02) (2, -4.85963486135005950928e-02) (3, -4.45801503956317901611e-02) (4, -9.35666561126708984375e-02) (5, -5.99919073283672332764e-02) (6, 9.85069200396537780762e-02) (7, -9.40151512622833251953e-03) (8, -3.15447002649307250977e-02) (9, -5.40914498269557952881e-02) (10, 4.16797772049903869629e-02) (11, 2.31406837701797485352e-03) (12, -7.02289417386054992676e-02) (13, -4.75645922124385833740e-02) (14, -4.49098832905292510986e-02) (15, -9.45371687412261962891e-02) (16, -4.31936569511890411377e-02) (17, -3.95005047321319580078e-02) (18, -1.51532292366027832031e-02) (19, -8.91426652669906616211e-02) (20, 2.55817249417304992676e-02) (21, 2.46212854981422424316e-02) (22, -2.50246450304985046387e-02) (23, 6.02161884307861328125e-03) (24, -3.54586392641067504883e-02) (25, -9.15261432528495788574e-02) (26, 4.98329475522041320801e-02) (0, -5.56833259761333465576e-02) (1, 8.57360661029815673828e-03) (2, 2.74457037448883056641e-04) (3, -8.28211233019828796387e-02) (4, -2.11838111281394958496e-02) (5, 4.01253774762153625488e-02) (6, -3.14174741506576538086e-02) (7, 3.42360362410545349121e-02) (8, 4.65587154030799865723e-02) (9, 8.59062373638153076172e-03) (10, 3.27429547905921936035e-02) (11, -6.28428012132644653320e-02) (12, 7.70459249615669250488e-02) (13, 7.86514952778816223145e-02) (14, 7.88369700312614440918e-02) (15, -2.06400007009506225586e-02) (16, -9.15774405002593994141e-02) (17, -6.87276199460029602051e-02) (18, 3.44501212239265441895e-02) (19, -8.61146152019500732422e-02) (20, -1.19212716817855834961e-02) (21, 9.49496105313301086426e-02) (22, -1.26784294843673706055e-03) (23, -1.06393545866012573242e-03) (24, 2.05313190817832946777e-02) (25, -7.66465589404106140137e-02) (26, 7.39114210009574890137e-02) (0, -7.34470486640930175781e-02) (1, -1.21052041649818420410e-02) (2, 8.23852643370628356934e-02) (3, 7.63858929276466369629e-02) (4, 3.22114750742912292480e-02) (5, -9.04112309217453002930e-03) (6, -2.33396515250205993652e-02) (7, 4.93903532624244689941e-02) (8, 6.97750523686408996582e-02) (9, -8.32142829895019531250e-02) (10, -8.20271149277687072754e-02) (11, 4.01109457015991210938e-03) (12, 6.33444264531135559082e-02) (13, 2.65635028481483459473e-02) (14, -6.32459521293640136719e-02) (15, -9.94983687996864318848e-02) (16, 3.60943377017974853516e-03) (17, -8.45944583415985107422e-02) (18, 7.93386027216911315918e-02) (19, 8.29694345593452453613e-02) (20, -7.61718973517417907715e-02) (21, -8.93890187144279479980e-02) (22, 1.74195393919944763184e-02) (23, -6.22865110635757446289e-02) (24, -1.31029635667800903320e-03) (25, 1.23691409826278686523e-02) (26, 3.64456549286842346191e-02) (0, 9.76257696747779846191e-02) (1, -6.70995265245437622070e-02) (2, 5.97990825772285461426e-02) (3, 7.15371891856193542480e-02) (4, -4.05465774238109588623e-02) (5, -5.23061156272888183594e-02) (6, 5.39224520325660705566e-02) (7, -6.41606822609901428223e-02) (8, 7.99053534865379333496e-02) (9, -5.51186725497245788574e-02) (10, 1.24996677041053771973e-02) (11, 2.92957052588462829590e-02) (12, -8.53436142206192016602e-02) (13, 2.92853936553001403809e-02) (14, 4.72685918211936950684e-02) (15, 1.86674818396568298340e-02) (16, -7.37017393112182617188e-03) (17, -2.61678993701934814453e-02) (18, 5.54215386509895324707e-02) (19, -6.86854124069213867188e-03) (20, 7.74415358901023864746e-02) (21, 7.08270743489265441895e-02) (22, -2.75299400091171264648e-02) (23, 6.04109689593315124512e-02) (24, 9.46551784873008728027e-02) (25, -1.69189572334289550781e-02) (26, -2.21695005893707275391e-02) (0, -6.76313340663909912109e-02) (1, 8.17707404494285583496e-02) (2, 9.01996567845344543457e-02) (3, 6.88143149018287658691e-02) (4, 7.93965086340904235840e-02) (5, -7.68998861312866210938e-02) (6, 2.86133959889411926270e-02) (7, 5.09336963295936584473e-02) (8, -1.74464657902717590332e-02) (9, 7.63072893023490905762e-02) (10, 4.85614687204360961914e-03) (11, 1.83928608894348144531e-02) (12, 5.62126561999320983887e-02) (13, 4.97374758124351501465e-02) (14, -6.91074728965759277344e-02) (15, -1.44916400313377380371e-02) (16, 6.43938705325126647949e-02) (17, 6.01779147982597351074e-02) (18, -6.72230422496795654297e-02) (19, -1.69386416673660278320e-02) (20, -4.71922643482685089111e-02) (21, 6.60905987024307250977e-03) (22, -6.15171156823635101318e-02) (23, 4.59391996264457702637e-02) (24, -1.59494131803512573242e-02) (25, -9.06900390982627868652e-02) (26, -8.15907418727874755859e-02) (0, -5.55384494364261627197e-02) (1, -9.60348621010780334473e-02) (2, 1.49029493331909179688e-03) (3, 2.22920551896095275879e-02) (4, -6.36661946773529052734e-02) (5, -1.67389586567878723145e-02) (6, 1.24916881322860717773e-02) (7, -9.48518812656402587891e-02) (8, -3.73424440622329711914e-02) (9, 3.55918034911155700684e-02) (10, 3.37615087628364562988e-02) (11, -8.64087417721748352051e-02) (12, -8.18546563386917114258e-02) (13, 1.00688114762306213379e-02) (14, 1.84474140405654907227e-02) (15, 3.65381911396980285645e-02) (16, -3.37185487151145935059e-02) (17, -3.18151190876960754395e-02) (18, 6.74307271838188171387e-02) (19, 5.17898127436637878418e-02) (20, -6.74212574958801269531e-02) (21, 2.76086404919624328613e-02) (22, 8.45667645335197448730e-02) (23, 1.56401023268699645996e-02) (24, 8.04163888096809387207e-02) (25, -8.82418453693389892578e-03) (26, 5.41229918599128723145e-02) (0, 2.63555720448493957520e-02) (1, 7.52264186739921569824e-02) (2, 6.34329393506050109863e-02) (3, 4.47648242115974426270e-02) (4, -8.03120359778404235840e-02) (5, 6.73980787396430969238e-02) (6, -5.37448748946189880371e-02) (7, 4.19800207018852233887e-02) (8, -9.62681099772453308105e-02) (9, 2.95161679387092590332e-02) (10, -4.55282926559448242188e-02) (11, -9.11199897527694702148e-02) (12, 9.21737328171730041504e-02) (13, 9.00635197758674621582e-02) (14, 4.26415279507637023926e-02) (15, -9.42350178956985473633e-02) (16, -9.17911455035209655762e-02) (17, -4.72896657884120941162e-02) (18, 2.42123976349830627441e-02) (19, 4.47470620274543762207e-02) (20, 1.89917832612991333008e-02) (21, 9.23972800374031066895e-02) (22, 1.21777877211570739746e-02) (23, -2.92184054851531982422e-02) (24, -7.50239789485931396484e-02) (25, -6.02135770022869110107e-02) (26, -4.46516387164592742920e-02) (0, 4.06161323189735412598e-02) (1, -7.97972008585929870605e-02) (2, 4.65241745114326477051e-02) (3, -5.26088476181030273438e-03) (4, 4.65583875775337219238e-02) (5, 2.17505916953086853027e-02) (6, -4.18279357254505157471e-02) (7, -8.67678970098495483398e-03) (8, 4.14385572075843811035e-02) (9, -7.44298473000526428223e-02) (10, 3.75783368945121765137e-02) (11, -1.65814310312271118164e-02) (12, -7.06979557871818542480e-02) (13, -3.29054966568946838379e-02) (14, 3.78902629017829895020e-02) (15, -6.18179440498352050781e-02) (16, -4.07317653298377990723e-02) (17, 2.79537811875343322754e-02) (18, 8.08235928416252136230e-02) (19, -3.49667817354202270508e-02) (20, 3.61626371741294860840e-02) (21, -6.64660781621932983398e-02) (22, 8.92456248402595520020e-02) (23, -1.90902948379516601562e-02) (24, 5.25257065892219543457e-02) (25, 8.16428884863853454590e-02) (26, 9.30874869227409362793e-02) (0, -7.66927003860473632812e-02) (1, -9.33810919523239135742e-02) (2, -6.71260952949523925781e-02) (3, -2.13443487882614135742e-02) (4, 4.72350344061851501465e-02) (5, -4.69232872128486633301e-02) (6, -7.48201608657836914062e-02) (7, -5.80258443951606750488e-02) (8, 9.96350869536399841309e-02) (9, 4.69304397702217102051e-02) (10, 1.46225094795227050781e-04) (11, -9.04170423746109008789e-03) (12, -1.16310194134712219238e-02) (13, 2.57163718342781066895e-02) (14, -7.14633613824844360352e-02) (15, 7.17875435948371887207e-02) (16, 5.50184324383735656738e-02) (17, -4.36885654926300048828e-03) (18, 9.67781245708465576172e-03) (19, 9.32004824280738830566e-02) (20, 5.48993721604347229004e-02) (21, -6.23684003949165344238e-02) (22, 7.40240588784217834473e-02) (23, -8.00674110651016235352e-02) (24, 7.37942531704902648926e-02) (25, -9.24420207738876342773e-02) (26, -9.08217951655387878418e-02) (0, -4.52960543334484100342e-02) (1, 6.00836947560310363770e-02) (2, 9.08210948109626770020e-02) (3, -5.22085689008235931396e-02) (4, 8.33909735083580017090e-02) (5, 9.74400117993354797363e-02) (6, -1.93346589803695678711e-02) (7, -3.79533655941486358643e-02) (8, 4.46750596165657043457e-02) (9, 3.37420627474784851074e-02) (10, -1.27735286951065063477e-02) (11, 8.66492018103599548340e-02) (12, 3.33771482110023498535e-02) (13, -6.58430978655815124512e-02) (14, -1.32045671343803405762e-02) (15, -7.56645500659942626953e-02) (16, 2.25258842110633850098e-02) (17, -8.74881967902183532715e-02) (18, -4.71279136836528778076e-02) (19, -5.68656623363494873047e-03) (20, 6.75302222371101379395e-02) (21, 4.85032275319099426270e-02) (22, -9.60087478160858154297e-02) (23, 6.07307031750679016113e-02) (24, 3.40260565280914306641e-03) (25, -5.83771429955959320068e-02) (26, 3.47547605633735656738e-02) (0, 2.33351960778236389160e-02) (1, -8.45829024910926818848e-02) (2, 4.23127487301826477051e-02) (3, 3.25134024024009704590e-02) (4, -2.98789590597152709961e-02) (5, 2.39642709493637084961e-03) (6, 2.33344882726669311523e-02) (7, 1.79124847054481506348e-02) (8, -1.42125859856605529785e-02) (9, 2.07744985818862915039e-02) (10, 9.85778197646141052246e-02) (11, 4.78340461850166320801e-02) (12, -3.45504507422447204590e-02) (13, 3.23198810219764709473e-02) (14, -6.49394765496253967285e-02) (15, -4.79012504220008850098e-02) (16, -3.43029648065567016602e-02) (17, -3.07825729250907897949e-02) (18, 3.88941839337348937988e-02) (19, -9.96751338243484497070e-03) (20, 9.17433127760887145996e-02) (21, 5.14059886336326599121e-02) (22, 4.29045632481575012207e-02) (23, -1.39432474970817565918e-02) (24, 1.89362168312072753906e-02) (25, -8.59220325946807861328e-03) (26, -9.95199382305145263672e-03) (0, -2.03330665826797485352e-02) (1, 9.48104038834571838379e-02) (2, 3.16708758473396301270e-02) (3, -8.55783000588417053223e-02) (4, 1.81455984711647033691e-02) (5, 4.70879748463630676270e-02) (6, 5.67344501614570617676e-02) (7, -4.93410043418407440186e-02) (8, -8.27909857034683227539e-02) (9, -4.08691167831420898438e-02) (10, 7.39934965968132019043e-02) (11, 3.51214930415153503418e-02) (12, 4.49183061718940734863e-02) (13, -5.23201376199722290039e-03) (14, 3.36993262171745300293e-02) (15, -7.24765658378601074219e-03) (16, 6.02175369858741760254e-02) (17, -3.39808017015457153320e-02) (18, 2.78128609061241149902e-02) (19, -8.76837149262428283691e-02) (20, 3.17162349820137023926e-02) (21, 9.70302894711494445801e-02) (22, 5.12104704976081848145e-02) (23, -7.82512798905372619629e-02) (24, 8.87736156582832336426e-02) (25, 2.61646509170532226562e-03) (26, 6.46532848477363586426e-02) (0, -2.51696333289146423340e-02) (1, -7.84473195672035217285e-02) (2, -4.39389050006866455078e-02) (3, 6.48783817887306213379e-02) (4, 1.21960788965225219727e-03) (5, -4.91285100579261779785e-02) (6, -3.45075875520706176758e-03) (7, 1.56413093209266662598e-02) (8, 6.90170899033546447754e-02) (9, -5.63627928495407104492e-02) (10, -2.76242420077323913574e-02) (11, -8.03239196538925170898e-02) (12, -3.91537807881832122803e-02) (13, 3.15066352486610412598e-02) (14, 9.36695709824562072754e-02) (15, 9.59677174687385559082e-02) (16, -2.35750675201416015625e-02) (17, -1.15624442696571350098e-02) (18, 2.96670272946357727051e-02) (19, 6.91772773861885070801e-02) (20, -5.13449050486087799072e-02) (21, 9.56862345337867736816e-02) (22, -3.00985574722290039062e-03) (23, -3.90286147594451904297e-02) (24, 2.74024680256843566895e-02) (25, -5.97955286502838134766e-03) (26, -8.78181457519531250000e-02) (0, 4.91511896252632141113e-02) (1, -1.72059461474418640137e-02) (2, 1.47983208298683166504e-02) (3, 1.38044804334640502930e-02) (4, 5.76244220137596130371e-02) (5, 3.63510027527809143066e-02) (6, 6.98655769228935241699e-02) (7, 2.25027948617935180664e-02) (8, -6.24293945729732513428e-02) (9, -7.92629346251487731934e-02) (10, -8.09479653835296630859e-02) (11, 5.32119199633598327637e-02) (12, 8.97541567683219909668e-02) (13, -3.73107567429542541504e-02) (14, -7.44123309850692749023e-02) (15, -9.05697643756866455078e-02) (16, 2.35354676842689514160e-02) (17, 5.70943132042884826660e-02) (18, -9.69001948833465576172e-02) (19, 1.95031762123107910156e-02) (20, -6.64807558059692382812e-02) (21, -8.46263021230697631836e-03) (22, -5.08297942578792572021e-02) (23, -9.73034799098968505859e-02) (24, 4.01924625039100646973e-02) (25, -5.51435649394989013672e-02) (26, -3.13334167003631591797e-04) (0, -9.88361537456512451172e-02) (1, 7.22588971257209777832e-02) (2, 9.37071070075035095215e-02) (3, -8.66542980074882507324e-02) (4, 2.14100852608680725098e-02) (5, -2.34988331794738769531e-02) (6, 2.81440094113349914551e-02) (7, -6.47854432463645935059e-02) (8, -6.58744126558303833008e-02) (9, -3.55049818754196166992e-02) (10, -9.49198678135871887207e-02) (11, 5.66283836960792541504e-02) (12, 2.06562131643295288086e-03) (13, -7.41828083992004394531e-02) (14, 7.56804272532463073730e-02) (15, -4.47224676609039306641e-02) (16, -8.44286531209945678711e-02) (17, -6.16303309798240661621e-02) (18, -1.91347971558570861816e-02) (19, -7.49984160065650939941e-02) (20, 6.19051381945610046387e-02) (21, -6.20404891669750213623e-02) (22, -7.18986093997955322266e-02) (23, -1.85916870832443237305e-02) (24, -2.85212472081184387207e-02) (25, 1.96387544274330139160e-02) (26, 3.05785313248634338379e-02) (0, -2.58247256278991699219e-02) (1, -4.01687808334827423096e-02) (2, 7.54349604249000549316e-02) (3, 7.38619491457939147949e-02) (4, -3.90049330890178680420e-02) (5, 4.76938560605049133301e-02) (6, 6.75690546631813049316e-02) (7, -2.56592333316802978516e-02) (8, -3.08960601687431335449e-02) (9, -5.59297837316989898682e-02) (10, -9.75152179598808288574e-02) (11, 4.31849807500839233398e-03) (12, -2.18041986227035522461e-02) (13, -3.30201983451843261719e-02) (14, 9.39862430095672607422e-03) (15, -6.51758164167404174805e-02) (16, 6.90454319119453430176e-02) (17, 3.52158173918724060059e-02) (18, -8.94953906536102294922e-02) (19, -7.56770372390747070312e-02) (20, 5.07871732115745544434e-02) (21, -5.11257201433181762695e-02) (22, 5.18816709518432617188e-03) (23, 7.57887586951255798340e-02) (24, -8.92205834388732910156e-02) (25, 4.31476905941963195801e-02) (26, -9.61098521947860717773e-02) (0, -7.81226903200149536133e-03) (1, -8.53735655546188354492e-02) (2, 2.35289111733436584473e-02) (3, -7.72337466478347778320e-02) (4, -1.11982896924018859863e-02) (5, 8.33601281046867370605e-02) (6, 9.82012227177619934082e-02) (7, -3.73363420367240905762e-02) (8, -5.56448064744472503662e-02) (9, 4.58950772881507873535e-02) (10, -6.97672888636589050293e-02) (11, 1.86959654092788696289e-02) (12, -8.50009843707084655762e-02) (13, -2.56970748305320739746e-02) (14, 2.11807489395141601562e-02) (15, 1.93175226449966430664e-02) (16, 5.24987354874610900879e-02) (17, 8.81605520844459533691e-02) (18, -7.12838545441627502441e-02) (19, 8.73229131102561950684e-02) (20, 5.72059825062751770020e-02) (21, 6.39319643378257751465e-02) (22, 9.78275313973426818848e-02) (23, 8.15289393067359924316e-02) (24, 1.47191435098648071289e-02) (25, -5.32981976866722106934e-02) (26, -1.32829025387763977051e-02) (0, -9.49209928512573242188e-03) (1, -4.25187759101390838623e-02) (2, -7.01352208852767944336e-02) (3, -5.60194998979568481445e-03) (4, 4.96689602732658386230e-02) (5, -5.55087886750698089600e-02) (6, -8.20730403065681457520e-02) (7, 7.24352076649665832520e-02) (8, 3.32929268479347229004e-02) (9, -9.87129136919975280762e-02) (10, 7.06364288926124572754e-02) (11, 9.59565863013267517090e-02) (12, -5.43577224016189575195e-02) (13, 1.65315046906471252441e-02) (14, -7.38107115030288696289e-02) (15, 6.43382444977760314941e-02) (16, 3.15305218100547790527e-02) (17, 4.92215156555175781250e-04) (18, -1.44810155034065246582e-02) (19, -4.91519644856452941895e-02) (20, -4.70090508460998535156e-02) (21, -2.63204649090766906738e-02) (22, -2.04358249902725219727e-02) (23, -5.96861355006694793701e-02) (24, -6.91144838929176330566e-02) (25, -5.65038546919822692871e-02) (26, -6.18586093187332153320e-02) (0, -8.75855535268783569336e-02) (1, 5.82152828574180603027e-02) (2, -1.51568055152893066406e-02) (3, -8.68454575538635253906e-04) (4, -5.12768141925334930420e-02) (5, 4.23244163393974304199e-02) (6, 2.89963260293006896973e-02) (7, 4.31212410330772399902e-02) (8, -8.00662487745285034180e-03) (9, 7.34875425696372985840e-02) (10, 6.10482022166252136230e-02) (11, -3.55714112520217895508e-02) (12, 6.78046792745590209961e-03) (13, 6.23352751135826110840e-02) (14, -6.49349838495254516602e-02) (15, 2.73706018924713134766e-03) (16, -9.20224413275718688965e-02) (17, 5.15965297818183898926e-02) (18, 2.89263501763343811035e-02) (19, 7.23158046603202819824e-02) (20, -1.68729573488235473633e-02) (21, -7.05814361572265625000e-02) (22, -4.21652160584926605225e-02) (23, 3.39750722050666809082e-02) (24, -1.75904855132102966309e-02) (25, 3.15143242478370666504e-02) (26, -8.64607393741607666016e-02) (0, 2.27233767509460449219e-02) (1, 6.23998418450355529785e-02) (2, -4.29645888507366180420e-02) (3, 6.08647689223289489746e-02) (4, 7.48142823576927185059e-02) (5, -8.47493037581443786621e-02) (6, -5.42920343577861785889e-02) (7, -2.60541588068008422852e-02) (8, -3.60261127352714538574e-02) (9, 8.80323722958564758301e-02) (10, -9.70578342676162719727e-02) (11, -9.29048806428909301758e-02) (12, -1.99742466211318969727e-02) (13, 7.64297172427177429199e-02) (14, 6.81433156132698059082e-02) (15, 4.44543436169624328613e-02) (16, -1.67898163199424743652e-02) (17, 3.04786041378974914551e-02) (18, 7.95193389058113098145e-02) (19, 8.59472379088401794434e-02) (20, 3.84561493992805480957e-02) (21, 3.11158671975135803223e-02) (22, 1.48735791444778442383e-02) (23, 1.07719525694847106934e-02) (24, -8.57570916414260864258e-02) (25, 4.42921444773674011230e-02) (26, 6.86067417263984680176e-02) (0, 4.82179895043373107910e-02) (1, -7.32983499765396118164e-02) (2, 1.21071934700012207031e-04) (3, 6.17572590708732604980e-02) (4, 4.94250282645225524902e-02) (5, -3.74790951609611511230e-02) (6, -8.12073424458503723145e-02) (7, 1.02898031473159790039e-02) (8, -6.26648068428039550781e-02) (9, -6.59566447138786315918e-02) (10, 5.59977665543556213379e-02) (11, 1.12810358405113220215e-02) (12, -1.98276340961456298828e-03) (13, 4.40301373600959777832e-02) (14, 1.42232030630111694336e-02) (15, 5.11236488819122314453e-03) (16, -7.59441107511520385742e-02) (17, -9.34708118438720703125e-03) (18, -2.67443209886550903320e-02) (19, 6.85102418065071105957e-02) (20, 7.38630965352058410645e-02) (21, -9.62657183408737182617e-02) (22, 4.80295792222023010254e-02) (23, 5.98103478550910949707e-02) (24, 4.21904399991035461426e-02) (25, -2.08545550704002380371e-02) (26, -2.53160744905471801758e-02) (0, -4.70376014709472656250e-02) (1, -6.61164522171020507812e-03) (2, -8.10239315032958984375e-02) (3, -7.84308612346649169922e-02) (4, -5.83936534821987152100e-02) (5, -5.43222837150096893311e-02) (6, 2.16902047395706176758e-02) (7, -9.66364070773124694824e-02) (8, 9.51027497649192810059e-02) (9, 8.42111185193061828613e-02) (10, -7.78437480330467224121e-02) (11, 5.39253652095794677734e-03) (12, -7.84536972641944885254e-02) (13, -4.38003912568092346191e-02) (14, -3.86096946895122528076e-02) (15, 3.28273400664329528809e-02) (16, 5.42168542742729187012e-02) (17, -9.45795550942420959473e-02) (18, -5.29494583606719970703e-02) (19, -4.06707897782325744629e-02) (20, -7.05236643552780151367e-02) (21, 3.77034619450569152832e-02) (22, 3.25848981738090515137e-02) (23, 9.79865714907646179199e-02) (24, 1.15665569901466369629e-02) (25, 3.63191887736320495605e-02) (26, 4.60161492228507995605e-02) (0, -2.86230966448783874512e-02) (1, -2.14903801679611206055e-02) (2, -7.48384073376655578613e-02) (3, 4.60608229041099548340e-02) (4, 3.14720347523689270020e-02) (5, 1.85499414801597595215e-02) (6, 6.50368854403495788574e-02) (7, 5.30411675572395324707e-02) (8, 6.01562932133674621582e-02) (9, -8.92853960394859313965e-02) (10, -2.52686291933059692383e-02) (11, 6.35198876261711120605e-02) (12, -9.41826477646827697754e-02) (13, -4.10575158894062042236e-02) (14, 8.56761410832405090332e-02) (15, 1.12098902463912963867e-02) (16, -1.95112079381942749023e-02) (17, -5.81242516636848449707e-02) (18, 7.26001933217048645020e-02) (19, -8.66838768124580383301e-02) (20, 9.60925891995429992676e-02) (21, 7.80206397175788879395e-02) (22, -3.96333299577236175537e-02) (23, -4.45781908929347991943e-02) (24, -9.25030186772346496582e-02) (25, 9.80701372027397155762e-02) (26, 8.80067124962806701660e-02) (0, -9.45164486765861511230e-02) (1, 9.63668525218963623047e-03) (2, 2.43258923292160034180e-02) (3, 5.14997020363807678223e-02) (4, 8.10135826468467712402e-02) (5, -9.71644818782806396484e-02) (6, 7.66612961888313293457e-02) (7, 2.70744040608406066895e-02) (8, 3.43075469136238098145e-02) (9, -4.78877127170562744141e-03) (10, -7.88870453834533691406e-03) (11, -1.26513019204139709473e-02) (12, -4.46324758231639862061e-02) (13, 2.82590091228485107422e-03) (14, 6.20800778269767761230e-02) (15, -8.11125859618186950684e-02) (16, 8.64325463771820068359e-03) (17, -7.89774507284164428711e-02) (18, -9.54364463686943054199e-02) (19, -8.01468417048454284668e-02) (20, 1.51135027408599853516e-03) (21, -5.35607002675533294678e-02) (22, 9.24533680081367492676e-02) (23, 1.48274675011634826660e-02) (24, -5.74681013822555541992e-02) (25, 7.04740062355995178223e-02) (26, 7.51941427588462829590e-02) (27, -2.04628705978393554688e-03) (28, 7.79709890484809875488e-02) (29, 7.32642635703086853027e-02) (30, -1.40395760536193847656e-02) (31, 8.34545567631721496582e-02) (32, -1.70990377664566040039e-02) (33, -8.97136852145195007324e-02) (34, 3.49542573094367980957e-02) (35, -3.60854491591453552246e-02) (36, -8.68781656026840209961e-02) (37, 1.16155371069908142090e-02) (38, 9.09889563918113708496e-02) (39, 4.74293753504753112793e-02) (40, -9.31732356548309326172e-02) (41, -1.68997421860694885254e-02) (42, -6.52219355106353759766e-02) (43, -3.78057062625885009766e-02) (44, 8.59261676669120788574e-02) (45, 9.68581512570381164551e-02) (46, -1.89182907342910766602e-02) (47, -5.43057918548583984375e-03) (48, -8.21193084120750427246e-02) (49, -1.43547430634498596191e-02) (50, 1.44225731492042541504e-02) (51, 1.93920359015464782715e-02) (52, 3.20845618844032287598e-02) (53, 6.87593221664428710938e-03) (54, -6.57804906368255615234e-02) (55, 7.46164545416831970215e-02) (56, -2.26500481367111206055e-02) (57, -9.05863568186759948730e-02) (27, -2.74298340082168579102e-02) (28, -4.46790568530559539795e-02) (29, 8.26779082417488098145e-02) (30, 5.85305914282798767090e-02) (31, -6.12245127558708190918e-02) (32, -3.44211235642433166504e-02) (33, 6.88169077038764953613e-02) (34, 7.37297311425209045410e-02) (35, 2.94934287667274475098e-02) (36, 8.19387510418891906738e-02) (37, -1.46547406911849975586e-02) (38, 2.04823836684226989746e-02) (39, 2.93681100010871887207e-02) (40, -7.82796740531921386719e-03) (41, -9.64173600077629089355e-02) (42, 6.41461834311485290527e-02) (43, 5.43663278222084045410e-02) (44, 8.95088091492652893066e-02) (45, 6.10043331980705261230e-02) (46, -6.45519718527793884277e-02) (47, -1.59217715263366699219e-02) (48, 7.88850262761116027832e-02) (49, 2.10932865738868713379e-02) (50, 9.85007956624031066895e-02) (51, -1.72294676303863525391e-03) (52, -4.68221567571163177490e-02) (53, 5.37674129009246826172e-03) (54, 3.24965640902519226074e-02) (55, -7.22056999802589416504e-02) (56, 8.27266946434974670410e-02) (57, 4.19102087616920471191e-02) (27, 3.64467501640319824219e-04) (28, -6.19523711502552032471e-02) (29, 2.45881229639053344727e-02) (30, -4.11049388349056243896e-02) (31, -2.31768861413002014160e-02) (32, 9.01669934391975402832e-02) (33, -7.22880214452743530273e-02) (34, -4.94471490383148193359e-02) (35, 1.96604281663894653320e-02) (36, -9.03492867946624755859e-02) (37, 3.58981117606163024902e-02) (38, -5.98571896553039550781e-02) (39, 3.90188321471214294434e-02) (40, -7.19298571348190307617e-02) (41, -5.62745444476604461670e-02) (42, 3.16502153873443603516e-03) (43, 8.24364647269248962402e-02) (44, -6.67657405138015747070e-02) (45, -3.58306616544723510742e-02) (46, -8.21155011653900146484e-02) (47, 1.73124894499778747559e-02) (48, -5.69456405937671661377e-02) (49, 3.89777943491935729980e-02) (50, 1.58132910728454589844e-02) (51, 4.13314178586006164551e-02) (52, 9.21556279063224792480e-02) (53, -7.88099616765975952148e-02) (54, -2.61720195412635803223e-02) (55, -8.00500661134719848633e-02) (56, -9.60832759737968444824e-02) (57, -8.42618122696876525879e-02) (27, 2.03144103288650512695e-02) (28, -5.80356456339359283447e-02) (29, 4.03263047337532043457e-02) (30, 7.92094692587852478027e-02) (31, 1.87874659895896911621e-02) (32, 3.04933115839958190918e-02) (33, -9.30785611271858215332e-02) (34, 6.93403258919715881348e-02) (35, -4.98462691903114318848e-02) (36, -8.34278389811515808105e-02) (37, 5.23843616247177124023e-03) (38, -9.70345735549926757812e-03) (39, 5.55909946560859680176e-02) (40, 3.33085730671882629395e-02) (41, 3.40219959616661071777e-02) (42, -4.12439890205860137939e-02) (43, 1.57450437545776367188e-02) (44, 6.72562643885612487793e-02) (45, 2.29253545403480529785e-02) (46, 3.36295440793037414551e-02) (47, -1.54312476515769958496e-02) (48, 6.59797117114067077637e-02) (49, -2.73926705121994018555e-02) (50, -9.96179580688476562500e-02) (51, 7.31112807989120483398e-03) (52, -3.52370440959930419922e-02) (53, -7.84279182553291320801e-02) (54, 8.11391100287437438965e-02) (55, -1.52871161699295043945e-02) (56, -7.45111927390098571777e-02) (57, 9.68772992491722106934e-02)
@@ -0,0 +1,49 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+
6
+ require 'best_of_tournament_engine'
7
+ require 'random_player'
8
+ require 'lazy_player'
9
+ require 'fann_player'
10
+ require 'pp'
11
+
12
+ @r=RandomPlayer.new
13
+ @l=LazyPlayer.new
14
+ @f=FannPlayer.new
15
+
16
+ @cycle_n_games=50
17
+ @big_n_games=150
18
+
19
+
20
+ def play_tourney n
21
+ t=BestOfTournamentEngine.new choose_players,n
22
+ t.start
23
+ return t
24
+ end
25
+
26
+ def choose_players
27
+ pl=rand(100)>50 ? [@f,@r] : [@f,@l]
28
+ pl.reverse! if rand(100)>50
29
+ return pl
30
+ end
31
+
32
+ while (true)
33
+ t=play_tourney(@cycle_n_games)
34
+ puts "\n\n"+t.summary
35
+ @f.learn!(t.games)
36
+ if rand(100)>95
37
+ puts t.summary
38
+ t=play_tourney(@big_n_games)
39
+ puts "\n\n------------------------------------------------------------------"
40
+ puts t.summary
41
+ puts "------------------------------------------------------------------"
42
+ # if !(t.winner==@f)
43
+ # puts "LEARNING"
44
+ # @f.learn!(t.games)
45
+ # end
46
+ puts "------------------------------------------------------------------"
47
+ @f.learn!(t.games)
48
+ end
49
+ end
@@ -0,0 +1,73 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+ require 'game_engine'
5
+ require 'random_player'
6
+ require 'lazy_player'
7
+ require 'random_neural_player'
8
+ require 'random_neural_player2'
9
+ require 'random_neural_player3'
10
+ require 'neural_player4'
11
+ require 'best_of_tournament_engine'
12
+ require 'yaml'
13
+
14
+ class Array
15
+ def to_s
16
+ result="["
17
+ self.each do |x|
18
+ result << x.to_s << ","
19
+ end
20
+ result=result[0..-2]
21
+ result << "]"
22
+ return result
23
+ end
24
+
25
+ end
26
+
27
+ i=0
28
+ x=3
29
+ p1=NeuralPlayer4.new
30
+ prime=true
31
+ #p1=YAML.load_file("5c0aa68e-d188-499e-8b6c-e73fd72f611e-1260.txt")
32
+
33
+ Kernel.trap("INT") do
34
+ puts("Saving "+p1.id+"-"+i.to_s+".txt")
35
+ File::open(p1.id+"-"+i.to_s+".txt","wb") do |file|
36
+ YAML.dump p1,file
37
+ end
38
+ exit
39
+ end
40
+
41
+ #prime
42
+ if prime
43
+ puts("Playing 25 random games to prime the neural player")
44
+ t=BestOfTournamentEngine.new [p1,RandomPlayer.new],25
45
+ t.start
46
+ p1.learn! t.games
47
+ end
48
+ while true
49
+ t=BestOfTournamentEngine.new [p1,p1],x
50
+ t.start
51
+ p1.learn! t.games
52
+
53
+ if i%20==0
54
+ t2=BestOfTournamentEngine.new [p1,RandomPlayer.new],15
55
+ t2.start
56
+ puts i.to_s + ">------------------------------------------------------------------"
57
+ puts t2.summary
58
+
59
+ end
60
+
61
+ if i%15 == 0
62
+ rand_player=rand(10)<5 ? RandomPlayer.new : LazyPlayer.new
63
+ puts i.to_s+" - Time for random"
64
+ t_random=rand(10) < 5 ? BestOfTournamentEngine.new([p1,rand_player],3) : BestOfTournamentEngine.new([rand_player,p1],3)
65
+ t_random.start
66
+ puts t_random.summary
67
+ if t_random.winner.id != p1.id
68
+ puts "LOST!! Learning ..."
69
+ p1.learn! t_random.games
70
+ end
71
+ end
72
+ i+=x
73
+ end
@@ -0,0 +1 @@
1
+ #gem library file
@@ -0,0 +1,62 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+ require 'neuro_gammon/base_player'
6
+
7
+ module NeuroGammon
8
+ class BaseNeuralPlayer < BasePlayer
9
+ attr_reader :n_inputs
10
+ attr_reader :n_outputs
11
+ attr_reader :learning_rate
12
+ attr_reader :hidden_layers
13
+
14
+ def initialize
15
+ super
16
+ init_net
17
+ end
18
+
19
+ def suggest_move board,dice,colour
20
+ moves=board.valid_moves(colour, dice)
21
+ best_move=nil
22
+ best_score=-99
23
+ moves.each do |move|
24
+ new_board_state=board.move(move,colour)
25
+ inp=generate_input_pattern(new_board_state)
26
+ out=run_net(inp)
27
+ score=evaluate_output(out,board,dice,colour)
28
+ if score>best_score
29
+ best_move=move
30
+ best_score=score
31
+ end
32
+ end
33
+ return best_move
34
+ end
35
+
36
+ protected
37
+
38
+ def generate_corpus games
39
+ corpus=[]
40
+ inputs=[]
41
+ outputs=[]
42
+ x=0
43
+ games.each do |game|
44
+ if game.white_player.id==id or game.black_player.id==id
45
+ game_colour=game.white_player.id==id ? Board::WHITE : Board::BLACK
46
+ states=game.board_states
47
+ states.each_index() do |x|
48
+ state=game.board_states[x]
49
+ inputs << generate_input_pattern(state)
50
+ outputs << generate_output_pattern(state,game)
51
+ end
52
+ print "."
53
+ else
54
+ raise Exception.new("None of these games belong to this player")
55
+ end
56
+ end
57
+ print "\n"
58
+ corpus << inputs << outputs
59
+ return corpus
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+ require 'rubygems'
6
+ require 'uuidtools'
7
+
8
+ module NeuroGammon
9
+ class BasePlayer
10
+ attr_accessor :id
11
+ attr_accessor :name
12
+
13
+ def initialize
14
+ @id=UUIDTools::UUID.random_create.to_s
15
+ @name=self.class.name
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,60 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+ require 'neuro_gammon/game_engine'
6
+
7
+ module NeuroGammon
8
+ class BestOfTournamentEngine
9
+ attr_reader :total_games
10
+ attr_reader :players
11
+ attr_reader :winners
12
+ attr_reader :games
13
+ def initialize players,total_games
14
+ raise Exception.new("Has to be 2 players only") if players.size!=2
15
+ @total_games=total_games
16
+ @players=players
17
+ @games=[]
18
+ @winners=[]
19
+ end
20
+
21
+ def reset
22
+ @games=[]
23
+ @winners=[]
24
+ end
25
+
26
+ def start
27
+ p=players.reverse
28
+ total_games.downto(1) do |n|
29
+ print("("<<n.to_s<<")")
30
+ eng=GameEngine.new(players[0],players[1])
31
+ @games << eng.play_game
32
+ @winners << eng.winner
33
+ p=players.reverse
34
+ end
35
+ end
36
+
37
+ def winner
38
+ max=-1
39
+ best=0
40
+ players.each_index do |i|
41
+ c=winners.select {|w| w==players[i]}.size
42
+ if (c>max)
43
+ max=c
44
+ best=i
45
+ end
46
+ end
47
+ return players[best]
48
+ end
49
+
50
+ def summary
51
+ result=""
52
+ players.each do |p|
53
+ c=winners.select {|w| w==p}.size
54
+ result << p.to_s << " won " << c.to_s << " games.\n"
55
+ end
56
+ return result
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,236 @@
1
+ #
2
+ # Copyright (C) 2008 Stuart Owen
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module NeuroGammon
18
+ class Board
19
+ BLACK=-1
20
+ WHITE=1
21
+
22
+ def initialize
23
+ @board_state=[-2,0,0,0,0,5,0,3,0,0,0,-5,5,0,0,0,-3,0,-5,0,0,0,0,2]
24
+ @bar=[0,0]
25
+ end
26
+
27
+ def state
28
+ [@board_state,@bar]
29
+ end
30
+
31
+ def bar_count colour
32
+ return colour==Board::BLACK ? bar_state[0] : bar_state[1]
33
+ end
34
+
35
+ def piece_count colour
36
+ result=0
37
+ board_state.each do |x|
38
+ result+=x.abs if (x/colour > 0)
39
+ end
40
+ result+=bar_count(colour)
41
+ return result;
42
+ end
43
+
44
+ def validate_move move,colour
45
+ valid_range=colour==WHITE ? (18..23) : (0..5)
46
+ start=move[0]
47
+ fin=move[1]
48
+
49
+ if (move[0]==-1)
50
+ raise Execption.new("No piece on the bar") if (bar_count(colour)==0)
51
+ raise Exception.new("Invalid destination") if !valid_range.include?(fin)
52
+ raise Exception.new("Wrong colour at destination") if board_state[fin]*colour < -1
53
+ elsif (move[1]==-1)
54
+ validate_bearing_off_move(move,colour)
55
+ else
56
+ raise Exception.new("Unable to move while there is a piece on the bar") if bar_count(colour)>0
57
+ raise Exception.new("Wrong colour at destination") if board_state[fin]*colour < -1
58
+ raise Exception.new("Move must specify start and end") if move.size!=2
59
+ raise Exception.new("Invalid start position") if not (0..23).to_a.include?(start)
60
+ raise Exception.new("Invalid destination position") if not (0..23).to_a.include?(fin)
61
+
62
+ if (colour==Board::WHITE)
63
+ raise Exception.new("Wrong direction for WHITE") if start<=fin
64
+ else
65
+ raise Exception.new("Wrong direction for BLACK") if start>=fin
66
+ end
67
+ raise Exception.new("Wrong colour at starting point") if board_state[start]/colour < 0
68
+ raise Exception.new("No piece at starting point") if board_state[start]==0
69
+ raise Exception.new("Destination is already full") if board_state[fin].abs >= 5
70
+ end
71
+
72
+
73
+ end
74
+
75
+ def move move,colour
76
+ old_state=Marshal.load(Marshal.dump(board_state))
77
+ old_bar=Marshal.load(Marshal.dump(@bar))
78
+ move!(move,colour)
79
+ result=state
80
+ @board_state=old_state
81
+ @bar=old_bar
82
+ return result
83
+ end
84
+
85
+ def move! move,colour,dice=nil
86
+ validate_move move,colour
87
+ start=move[0]
88
+ fin=move[1]
89
+ if start==-1
90
+ Board::BLACK==colour ? @bar[0]-=1 : @bar[1]-=1
91
+ elsif fin==-1
92
+ @board_state[start]-=colour
93
+ else
94
+ @board_state[start]-=colour
95
+ end
96
+
97
+ if fin!=-1
98
+ @board_state[fin]+=colour
99
+ if (board_state[fin]==0)
100
+ @board_state[fin]+=colour
101
+ Board::BLACK==colour ? @bar[1]+=1 : @bar[0]+=1
102
+ end
103
+ end
104
+
105
+ if !dice.nil?
106
+ update_dice(dice, move)
107
+ end
108
+ end
109
+
110
+ def bearing_off? colour
111
+ return false if bar_count(colour)!=0
112
+ range=Board::BLACK==colour ? (18..23) : (0..5)
113
+ (0..23).each do |i|
114
+ if not range.include?(i)
115
+ return false if board_state[i]*colour>0
116
+ end
117
+ end
118
+ return true
119
+ end
120
+
121
+ def valid_moves colour,dice
122
+ result=[]
123
+ if (bar_count(colour)>0)
124
+ dice.to_a.uniq.each do |d|
125
+ dest=colour==Board::BLACK ? d-1 : 24-d
126
+ if board_state[dest]*colour >= -1 and board_state[dest]*colour < 5
127
+ result << [-1,dest]
128
+ end
129
+ end
130
+ else
131
+ dice.to_a.uniq.each do |d|
132
+ occupied_spaces(colour).each do |x|
133
+ dest=x+d*-colour
134
+ if ((0..23).include?(dest))
135
+ if board_state[dest]*colour >= -1 and board_state[dest]*colour < 5
136
+ result << [x,dest]
137
+ end
138
+ end
139
+ end
140
+ if (bearing_off?(colour))
141
+ bearing_off_range=colour==Board::BLACK ? (18..23).to_a : (0..5).to_a.reverse
142
+ bearing_off_range.each do |x|
143
+ dest=x+d*-colour
144
+ if board_state[x]*colour>0
145
+ if (!bearing_off_range.include?(dest))
146
+ if board_state[x]*colour>0
147
+ result << [x,-1]
148
+ break
149
+ end
150
+ else
151
+ break
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
158
+ return result
159
+ end
160
+
161
+ def winner
162
+ return Board::WHITE if piece_count(Board::WHITE)==0
163
+ return Board::BLACK if piece_count(Board::BLACK)==0
164
+ return nil
165
+ end
166
+
167
+ protected
168
+
169
+ def board_state
170
+ @board_state
171
+ end
172
+
173
+ def bar_state
174
+ @bar
175
+ end
176
+
177
+ private
178
+
179
+ def validate_bearing_off_move move,colour
180
+ range=colour==Board::BLACK ? (18..23) : (0..5)
181
+ start=move[0]
182
+ raise Exception.new("Not in a position to bear off") if !bearing_off?(colour)
183
+ raise Exception.new("Not a valid start position for bearing off") if not range.include?(start)
184
+ raise Exception.new("No piece of the right colour at the start position") if board_state[start]*colour <= 0
185
+ end
186
+
187
+
188
+
189
+ def occupied_spaces colour
190
+ raise Exception.new("Cannot count occupied spaces with piece on bar") if bar_count(colour)>0
191
+ result=[]
192
+ board_state.each_index do |i|
193
+ if board_state[i]*colour > 0
194
+ result << i
195
+ end
196
+ end
197
+ return result
198
+ end
199
+
200
+ def update_dice dice,move
201
+ #FIXME needs some unit testing
202
+ if (move[0]==-1) #off bar
203
+ dest=move[1]
204
+ v=0
205
+ if (move[1]<=5) #TODO should throw exception when the wrong colour
206
+ v=dest+1
207
+ else
208
+ v=24-dest
209
+ end
210
+ dice.use!(v)
211
+ elsif (move[1]==-1)
212
+ #works - but hacked in a hotel room after a couple of beers - needs tidying.
213
+ start=move[0]
214
+ dist=-1
215
+ v=0
216
+ if (start<=5) #TODO should throw exception when the wrong colour
217
+ dist=start+1
218
+ else
219
+ dist=24-start
220
+ end
221
+ sorted=dice.to_a.sort
222
+ sorted.each do |s|
223
+ if s>= dist
224
+ v=s
225
+ break
226
+ end
227
+ end
228
+ dice.use!(v) if v!=0
229
+ else
230
+ v=(move[0]-move[1]).abs
231
+ dice.use!(v)
232
+ end
233
+ end
234
+
235
+ end
236
+ end