#1776 Le 15/08/2012, à 08:32
- tshirtman
Re : /* Topic des codeurs [7] */
Ruby non plus (à part peut-être quand Ruby 2.0 aura apporté les .pyc à la Ruby mais j'suis pas sûr que ça change grand chose...).
J'ai exécuté mon truc SMA_FIGHTRuby sur une machine à base d'Atom (à 2 Ghz, 4 Gio de RAM), ben ça ramait à mort (genre 1 FPS par seconde), alors que le truc en Flash fonctionne très bien.
Hu-mi-lié. Par Flash. Sous GNU/Linux. Juste WAT ?!Y'a un sérieux problème, là...
T'as testé USF sur cette machine ? je suis sur que ça tourne très bien, oh, et kivy aussi (mais bon, kivy c'est bourré de cython sur les parties sensibles en perfs, ça aide ).
Hors ligne
#1777 Le 15/08/2012, à 08:34
- The Uploader
Re : /* Topic des codeurs [7] */
Non j'ai pas testé (et là je peux pas) mais ce serait intéressant.
J'ai une autre machine poussive à base d'Atom à laquelle j'ai accès le week end sinon (un asus eeePC 1015HA. Unity 2D/3D, KDE4, ou Aero ça le fait chauffer à mort. Par contre Xfce ça va. )
M'enfin entre Ruby qui prend 50% 85% (O_o) du CPU sur un Core2Duo T5800 pour afficher des cercles à 30 FPS, et des CPU Atom poussifs sur lesquels apt se roule par terre de douleur, je sais pas trop lequel est le plus fautif...
Dernière modification par The Uploader (Le 15/08/2012, à 08:40)
- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10
Hors ligne
#1778 Le 15/08/2012, à 09:15
- tshirtman
Re : /* Topic des codeurs [7] */
Ah mais apt (et bien plus encore, aptitude) ont des algos de résolution de dépendances un peux coûteux… donc c'est pas tout à fait anormal…
Cela dit, dans usf, c'est l'IA qui bouffe le plus, par ce que la seul approche qui m'a semblé viable à l'époque (et j'ai pas retouché depuis) demande de simuler de jeu sur plusieurs secondes avec tous les mouvements possibles, entre deux frames, bien sur, je le fais pas à toutes les frames, mais ça coute quand même… sans IA je pense que ça doit encore tourner sur un celeron
Hors ligne
#1779 Le 15/08/2012, à 09:18
- The Uploader
Re : /* Topic des codeurs [7] */
Le truc, c'est que j'ai même pas encore l'IA (m'enfin les systèmes experts devraient pas bouffer beaucoup. C'est juste "si x [et y, z...] sont vrais, alors cette règle est vrai", et ensuite faire l'action machin si toutes ses règles sont vraies...
edit : Tiens j'pensais que USF avait des systèmes experts..
Dernière modification par The Uploader (Le 15/08/2012, à 09:25)
- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10
Hors ligne
#1780 Le 15/08/2012, à 09:32
- grim7reaper
Re : /* Topic des codeurs [7] */
Ah mais apt (et bien plus encore, aptitude) ont des algos de résolution de dépendances un peux coûteux… donc c'est pas tout à fait anormal…
C’est toujours vrai cette grosse différence entre les deux ?
simuler de jeu sur plusieurs secondes avec tous les mouvements possibles, entre deux frames
Ha ouais, quand même :-/
@The Uploader :
Couldn't open data/bg_start_menu.png (Rubygame::SDLError)
Je crois qu’il manque une ressource dans data (pour gauge).
Hors ligne
#1781 Le 15/08/2012, à 09:34
- The Uploader
Re : /* Topic des codeurs [7] */
@grim ': fixed.
edit :
Tiens j'ai un peu optimisé mon SMA_FIGHTRuby quand même (ça change pas grand chose...)
commit 5026eca89386e3ba8c42ab372f88da1d22676f47
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Wed Aug 15 10:37:36 2012 +0200
Useless call of draw_sprite at each update...
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/MASWithTwoNests/bot.rb b/MASWithTwoNests/bot.rb
index aea5434..da79359 100644
--- a/MASWithTwoNests/bot.rb
+++ b/MASWithTwoNests/bot.rb
@@ -67,7 +67,6 @@ module MASWithTwoNests
end
def update(tick, world)
- draw_sprite
update_facts
infer
act
commit eeaf8bbc7260a7dfe359d5e463686a22a316e926
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Wed Aug 15 09:16:32 2012 +0200
Faster querying of bots collisions with agents
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/MASWithTwoNests/bot_team.rb b/MASWithTwoNests/bot_team.rb
index 0a32d51..3789335 100644
--- a/MASWithTwoNests/bot_team.rb
+++ b/MASWithTwoNests/bot_team.rb
@@ -11,7 +11,9 @@ require 'bot_home'
module MASWithTwoNests
class BotTeam < Agent
attr_reader :team_id
+ attr_reader :bots
def initialize(world, team_id, color, bot_types, bot_count)
+ @bots = []
@world = world
@team_id = team_id
@color = color
@@ -37,6 +39,7 @@ module MASWithTwoNests
bot.current_point = Point.new(Random.rand * World::WIDTH, Random.rand * World::HEIGHT)
end
@world.agents << bot
+ @bots << bot
end
end
end
diff --git a/MASWithTwoNests/world.rb b/MASWithTwoNests/world.rb
index 6a9e4df..99ecce2 100644
--- a/MASWithTwoNests/world.rb
+++ b/MASWithTwoNests/world.rb
@@ -47,6 +47,7 @@ module MASWithTwoNests
@bot_start_from_home = bot_start_from_home
@background = Rubygame::Surface.new([WIDTH, HEIGHT])
@agents = Rubygame::Sprites::Group.new
+ @bot_teams = []
Rubygame::Sprites::UpdateGroup.extend_object @agents
RESOURCE_COUNT.times do
resource = Resource.new(self, RESOURCE_START_LIFE, RESOURCE_MOVE_DELAY * Random.rand, RESOURCE_MOVE_SPEED * Random.rand)
@@ -54,6 +55,7 @@ module MASWithTwoNests
@agents << resource
end
bot_team = BotTeam.new(self, "DefaultTeam", Rubygame::Color::ColorRGB.new([0.4, 0.4, 0.4]), [AgentType::AGENT_BOT], BOT_COUNT/2)
+ @bot_teams << bot_team
end
def update(tick)
@@ -72,11 +74,13 @@ module MASWithTwoNests
end
def check_collisions
- @agents.each do |i|
- @agents.each do |j|
- if i.collide(j)
- i.on_collide(j) if i.respond_to?('on_collide') and (i.is_collided?(j) or i.is_perceived?(j))
- next
+ @bot_teams.each do |bot_team|
+ others = @agents - bot_team.bots
+ bot_team.bots.each do |bot|
+ others.each do |agent|
+ if bot.collide(agent)
+ bot.on_collide(agent) if (bot.is_collided?(agent) or bot.is_perceived?(agent))
+ end
end
end
end
Autres changements :
commit 95d050a32605226a67d3399ced330771f4b232ff
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Wed Aug 15 09:22:48 2012 +0200
Kernel#rand instead of Random.rand
As Random.rand is Ruby >= 1.9.2
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/MASWithTwoNests/agent.rb b/MASWithTwoNests/agent.rb
index 4c6a0ca..8289332 100644
--- a/MASWithTwoNests/agent.rb
+++ b/MASWithTwoNests/agent.rb
@@ -30,9 +30,9 @@ module MASWithTwoNests
end
def change_direction
- @direction = Point.new(Random.rand, Random.rand)
- @direction.x = @direction.x.to_i - 1 if Random.rand > 0.5
- @direction.y = @direction.y.to_i - 1 if Random.rand > 0.5
+ @direction = Point.new(rand, rand)
+ @direction.x = @direction.x.to_i - 1 if rand > 0.5
+ @direction.y = @direction.y.to_i - 1 if rand > 0.5
@direction.normalize!
end
end
diff --git a/MASWithTwoNests/bot_home.rb b/MASWithTwoNests/bot_home.rb
index f473e1d..49b7512 100644
--- a/MASWithTwoNests/bot_home.rb
+++ b/MASWithTwoNests/bot_home.rb
@@ -20,7 +20,7 @@ module MASWithTwoNests
@rect = @image.make_rect
@image.set_colorkey([0, 0, 0])
@image.draw_circle_s(@rect.center, World::HOME_RADIUS, Rubygame::Color::ColorRGB.new([0.22745, 0.22745, 0.22745, 1]))
- @rect.center = [Random.rand * World::HEIGHT, Random.rand * World::HEIGHT]
+ @rect.center = [rand * World::HEIGHT, rand * World::HEIGHT]
end
def update(tick, world)
diff --git a/MASWithTwoNests/bot_team.rb b/MASWithTwoNests/bot_team.rb
index 3789335..0c7e961 100644
--- a/MASWithTwoNests/bot_team.rb
+++ b/MASWithTwoNests/bot_team.rb
@@ -36,7 +36,7 @@ module MASWithTwoNests
if world.bot_start_from_home
bot.current_point = team_home.current_point
else
- bot.current_point = Point.new(Random.rand * World::WIDTH, Random.rand * World::HEIGHT)
+ bot.current_point = Point.new(rand * World::WIDTH, rand * World::HEIGHT)
end
@world.agents << bot
@bots << bot
diff --git a/MASWithTwoNests/resource.rb b/MASWithTwoNests/resource.rb
index 485084d..7a81d6c 100644
--- a/MASWithTwoNests/resource.rb
+++ b/MASWithTwoNests/resource.rb
@@ -16,7 +16,7 @@ module MASWithTwoNests
@update_time = 0
@speed = speed
if World::RESOURCE_RANDOM_START_LIFE
- @life = life * Random.rand + World::RESOURCE_UPDATE_VALUE
+ @life = life * rand + World::RESOURCE_UPDATE_VALUE
else
@life = life
end
@@ -24,7 +24,7 @@ module MASWithTwoNests
@rect = @image.make_rect
@image.set_colorkey([0, 0, 0])
@image.draw_circle_s(@rect.center, (World::RESOURCE_LIFE_RADIUS_COEFF * @life), Rubygame::Color::ColorRGB.new([0.8, 0.8 , 0.8, 1])) if @life > 0
- @rect.center = [Random.rand * World::HEIGHT, Random.rand * World::HEIGHT]
+ @rect.center = [rand * World::HEIGHT, rand * World::HEIGHT]
change_direction
end
diff --git a/MASWithTwoNests/world.rb b/MASWithTwoNests/world.rb
index 99ecce2..9adadfc 100644
--- a/MASWithTwoNests/world.rb
+++ b/MASWithTwoNests/world.rb
@@ -50,8 +50,8 @@ module MASWithTwoNests
@bot_teams = []
Rubygame::Sprites::UpdateGroup.extend_object @agents
RESOURCE_COUNT.times do
- resource = Resource.new(self, RESOURCE_START_LIFE, RESOURCE_MOVE_DELAY * Random.rand, RESOURCE_MOVE_SPEED * Random.rand)
- resource.target_point = Point.new(Random.rand * WIDTH, Random.rand * HEIGHT)
+ resource = Resource.new(self, RESOURCE_START_LIFE, RESOURCE_MOVE_DELAY * rand, RESOURCE_MOVE_SPEED * rand)
+ resource.target_point = Point.new(rand * WIDTH, rand * HEIGHT)
@agents << resource
end
bot_team = BotTeam.new(self, "DefaultTeam", Rubygame::Color::ColorRGB.new([0.4, 0.4, 0.4]), [AgentType::AGENT_BOT], BOT_COUNT/2)
commit d2583480367a569809f8f32435847abb0afbca7f
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Wed Aug 15 09:15:26 2012 +0200
Require rubygems, plus some cosmetic changes
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/CustomTeam/custom_bot.rb b/CustomTeam/custom_bot.rb
index 291fcde..a1ab31f 100644
--- a/CustomTeam/custom_bot.rb
+++ b/CustomTeam/custom_bot.rb
@@ -22,4 +22,6 @@ module CustomTeam
def on_collide(agent)
super
end
+ end
end
+
diff --git a/ExpertSystem/fact.rb b/ExpertSystem/fact.rb
index 63c30a4..b5bac33 100644
--- a/ExpertSystem/fact.rb
+++ b/ExpertSystem/fact.rb
@@ -9,4 +9,4 @@ module ExpertSystem
fact.label == @label
end
end
-end
\ No newline at end of file
+end
diff --git a/ExpertSystem/fact_base.rb b/ExpertSystem/fact_base.rb
index 45c4246..e5995d0 100644
--- a/ExpertSystem/fact_base.rb
+++ b/ExpertSystem/fact_base.rb
@@ -12,4 +12,4 @@ module ExpertSystem
return false
end
end
-end
\ No newline at end of file
+end
diff --git a/ExpertSystem/rule.rb b/ExpertSystem/rule.rb
index 34d929b..2572d97 100644
--- a/ExpertSystem/rule.rb
+++ b/ExpertSystem/rule.rb
@@ -7,4 +7,4 @@ module ExpertSystem
@premises = premises
end
end
-end
\ No newline at end of file
+end
diff --git a/ExpertSystem/rule_base.rb b/ExpertSystem/rule_base.rb
index a720b5d..9aa1b84 100644
--- a/ExpertSystem/rule_base.rb
+++ b/ExpertSystem/rule_base.rb
@@ -9,4 +9,4 @@ module ExpertSystem
@rules << rule
end
end
-end
\ No newline at end of file
+end
diff --git a/MASWithTwoNests/agent.rb b/MASWithTwoNests/agent.rb
index d9cf74c..4c6a0ca 100644
--- a/MASWithTwoNests/agent.rb
+++ b/MASWithTwoNests/agent.rb
@@ -1,3 +1,4 @@
+require 'rubygems'
require 'rubygame'
$LOAD_PATH << '../'
require 'lib/point'
diff --git a/MASWithTwoNests/agent_facts.rb b/MASWithTwoNests/agent_facts.rb
index 8814f0e..84f53b0 100644
--- a/MASWithTwoNests/agent_facts.rb
+++ b/MASWithTwoNests/agent_facts.rb
@@ -21,4 +21,4 @@ module MASWithTwoNests
TAKE_RESOURCE = Fact.new("Taking Resource.")
PUT_DOWN_RESOURCE = Fact.new("Putting down Resource.")
end
-end
\ No newline at end of file
+end
diff --git a/MASWithTwoNests/bot.rb b/MASWithTwoNests/bot.rb
index 304e1f7..aea5434 100644
--- a/MASWithTwoNests/bot.rb
+++ b/MASWithTwoNests/bot.rb
@@ -1,3 +1,4 @@
+require 'rubygems'
$LOAD_PATH << '../'
require 'lib/point'
include Lib
diff --git a/MASWithTwoNests/bot_home.rb b/MASWithTwoNests/bot_home.rb
index a1049ea..f473e1d 100644
--- a/MASWithTwoNests/bot_home.rb
+++ b/MASWithTwoNests/bot_home.rb
@@ -1,3 +1,4 @@
+require 'rubygems'
$LOAD_PATH << '../'
require 'lib/point'
include Lib
diff --git a/MASWithTwoNests/bot_team.rb b/MASWithTwoNests/bot_team.rb
index 38a66b7..0a32d51 100644
--- a/MASWithTwoNests/bot_team.rb
+++ b/MASWithTwoNests/bot_team.rb
@@ -1,3 +1,4 @@
+require 'rubygems'
$LOAD_PATH << '../'
require 'lib/point'
include Lib
diff --git a/MASWithTwoNests/main.rb b/MASWithTwoNests/main.rb
index 593d64c..c99acc9 100644
--- a/MASWithTwoNests/main.rb
+++ b/MASWithTwoNests/main.rb
@@ -1,3 +1,4 @@
+require 'rubygems'
require 'rubygoo'
require 'rubygame'
include Rubygame
diff --git a/MASWithTwoNests/resource.rb b/MASWithTwoNests/resource.rb
index c8fbaaf..485084d 100644
--- a/MASWithTwoNests/resource.rb
+++ b/MASWithTwoNests/resource.rb
@@ -1,3 +1,4 @@
+require 'rubygems'
$LOAD_PATH << '../'
require 'lib/point'
include Lib
diff --git a/MASWithTwoNests/world.rb b/MASWithTwoNests/world.rb
index 90eefc8..6a9e4df 100644
--- a/MASWithTwoNests/world.rb
+++ b/MASWithTwoNests/world.rb
@@ -1,3 +1,4 @@
+require 'rubygems'
require 'rubygoo'
require 'rubygame'
include Rubygame
diff --git a/tests/test_main.rb b/tests/test_main.rb
index 574b0ca..374fa9d 100644
--- a/tests/test_main.rb
+++ b/tests/test_main.rb
@@ -1,3 +1,4 @@
+require 'rubygems'
gem 'test-unit'
require 'test/unit'
require 'rubygoo'
@@ -16,4 +17,4 @@ class TestMain < Test::Unit::TestCase
def test_has_app
assert_equal Rubygoo::App, @main.instance_variable_get(:@app).class
end
-end
\ No newline at end of file
+end
diff --git a/tests/test_world.rb b/tests/test_world.rb
index d07df59..5f55ea2 100644
--- a/tests/test_world.rb
+++ b/tests/test_world.rb
@@ -1,3 +1,4 @@
+require 'rubygems'
gem 'test-unit'
require 'test/unit'
require 'rubygoo'
Dernière modification par The Uploader (Le 15/08/2012, à 09:42)
- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10
Hors ligne
#1782 Le 15/08/2012, à 09:43
- grim7reaper
Re : /* Topic des codeurs [7] */
Ça fonctionne , et j’ai l’impression que la conso’ est meilleure qu’avant (bien que ça ne fasse toujours pas grand chose ^^).
Édit : je parle pour gauge.
Dernière modification par grim7reaper (Le 15/08/2012, à 09:47)
Hors ligne
#1783 Le 15/08/2012, à 09:50
- The Uploader
Re : /* Topic des codeurs [7] */
Ça doit venir principalement de ce commit :
commit 935452294e2fa7fb39b4855bc1e58cf616c62956
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Fri Apr 20 18:44:25 2012 +0200
Use self.send instead of eval (faster/more secure)
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
lib/listener.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(en tout cas à part ça je vois pas ^^)
Dernière modification par The Uploader (Le 15/08/2012, à 09:52)
- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10
Hors ligne
#1784 Le 15/08/2012, à 09:56
- tshirtman
Re : /* Topic des codeurs [7] */
tshirtman a écrit :Ah mais apt (et bien plus encore, aptitude) ont des algos de résolution de dépendances un peux coûteux… donc c'est pas tout à fait anormal…
C’est toujours vrai cette grosse différence entre les deux ?
Je crois oui, je n'utilise plus aptitude, et j'ai vu passer quelques blogposts à propos de tentatives d'optimisation pour lui, mais je l'approche fondamentale n'a pas changé je crois.
tshirtman a écrit :simuler de jeu sur plusieurs secondes avec tous les mouvements possibles, entre deux frames
Ha ouais, quand même :-/
Oui, c'est lourd, j'essaye de faire un genre de A*, mais comme les déplacements ne sont pas prédictibles (c'est l'ajout d'un vecteur à l'entité à un instant T, puis les forces physiques normales, gravitation/frotement de l'air/poussée d’Archimède, et sachant que des bouts de niveaux se déplacent en cours de partis, on ne peut pas vraiment précalculer les sauts possibles, etc), donc là tous mes objects ont des methodes backup/restore, et le jeu est fast-forwardé puis resetté en position initiale pour chaque mouvement possible avant de continuer… ça marche bien, mais c'est quand même un peu lourd, et en plus, mes fonctions heuristiques sont peut être pas terribles, donc ils sont pas spécialement intelligents… >_<, mais bon, j'y ai pas touché depuis longtemps, je suis à fond sur kivy et les sous projets de kivy en ce moment, y'a tellement à faire et a apprendre, USF ne reçois pas beaucoup de soins…
Dernière modification par tshirtman (Le 15/08/2012, à 09:57)
Hors ligne
#1785 Le 15/08/2012, à 10:53
- The Uploader
Re : /* Topic des codeurs [7] */
Haha, on dirait que ça porte ses fruits... :
commit 7d4419d91a17941d81d9c6dbc4adeee67af5cb70 (HEAD, refs/remotes/origin/master, refs/heads/master)
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Wed Aug 15 11:49:49 2012 +0200
Even more faster world's agents collision/perception querying
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
---
MASWithTwoNests/bot.rb | 23 ++++++++++++-----------
MASWithTwoNests/world.rb | 29 ++++++++++++++++++++++++-----
2 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/MASWithTwoNests/bot.rb b/MASWithTwoNests/bot.rb
index da79359..c8a820b 100644
--- a/MASWithTwoNests/bot.rb
+++ b/MASWithTwoNests/bot.rb
@@ -102,17 +102,17 @@ module MASWithTwoNests
return (Point.distance(agent.current_point, current_point) <= @perception_radius)
end
- def on_collide(agent)
- if is_collided? agent
- if agent.class == Resource
- @reached_resource = agent
- end
- else
- if agent.class == Resource
- #The last reached resource can't be seen
- if agent != @last_reached_resource or @last_reached_resource == nil
- @seen_resource = agent
- end
+ def on_collision(agent)
+ if agent.class == Resource
+ @reached_resource = agent
+ end
+ return agent
+ end
+
+ def on_perception(agent)
+ if agent.class == Resource
+ if agent != @last_reached_resource or @last_reached_resource == nil
+ @seen_resource = agent
end
end
@@ -122,6 +122,7 @@ module MASWithTwoNests
@home_position = agent.current_point
end
end
+ return agent
end
def infer
diff --git a/MASWithTwoNests/world.rb b/MASWithTwoNests/world.rb
index 9adadfc..bb05337 100644
--- a/MASWithTwoNests/world.rb
+++ b/MASWithTwoNests/world.rb
@@ -74,14 +74,17 @@ module MASWithTwoNests
end
def check_collisions
+ notified_bots = []
@bot_teams.each do |bot_team|
- others = @agents - bot_team.bots
- bot_team.bots.each do |bot|
- others.each do |agent|
- if bot.collide(agent)
- bot.on_collide(agent) if (bot.is_collided?(agent) or bot.is_perceived?(agent))
+ others = (@agents - bot_team.bots) - notified_bots
+ if others.any?
+ bot_team.bots.each do |bot|
+ others.each do |agent|
+ notify_bot(bot, agent, notified_bots)
end
end
+ else
+ break
end
end
end
@@ -89,5 +92,21 @@ module MASWithTwoNests
def is_out?(target_point)
return true if (( target_point.x <= 0 || target_point.x >= WIDTH) || target_point.y <= 0 || target_point.y >= HEIGHT)
end
+
+ private
+
+ def notify_bot(bot, agent, notified_bots, bot_check = true)
+ notified = nil
+ if bot.is_collided?(agent)
+ notified = bot.on_collision(agent)
+ end
+ if bot.is_perceived?(agent)
+ notified = bot.on_perception(agent)
+ end
+ notified_bots << bot if notified
+ if bot_check and agent.class.ancestors.include?(Bot)
+ notify_bot(agent, bot, false)
+ end
+ end
end
end
Benchmark.measure { check_collisions } (avant/après) :
0.020000 0.000000 0.020000 ( 0.025181)
0.020000 0.000000 0.020000 ( 0.029962)
0.020000 0.000000 0.020000 ( 0.021982)
0.010000 0.000000 0.010000 ( 0.018491)
0.010000 0.000000 0.010000 ( 0.011994)
0.020000 0.000000 0.020000 ( 0.039933)
0.020000 0.000000 0.020000 ( 0.021036)
0.020000 0.000000 0.020000 ( 0.024517)
0.020000 0.000000 0.020000 ( 0.029888)
0.020000 0.000000 0.020000 ( 0.022111)
0.010000 0.000000 0.010000 ( 0.012913)
0.010000 0.000000 0.010000 ( 0.012464)
0.020000 0.000000 0.020000 ( 0.020269)
0.020000 0.000000 0.020000 ( 0.026070)
0.020000 0.000000 0.020000 ( 0.031910)
0.020000 0.000000 0.020000 ( 0.023180)
0.020000 0.000000 0.020000 ( 0.022873)
0.010000 0.000000 0.010000 ( 0.013965)
0.020000 0.000000 0.020000 ( 0.012168)
0.010000 0.000000 0.010000 ( 0.011737)
0.030000 0.000000 0.030000 ( 0.023263)
0.010000 0.000000 0.010000 ( 0.017426)
0.020000 0.000000 0.020000 ( 0.020458)
0.010000 0.000000 0.010000 ( 0.011456)
0.010000 0.000000 0.010000 ( 0.010762)
0.010000 0.000000 0.010000 ( 0.018506)
0.020000 0.000000 0.020000 ( 0.019370)
0.020000 0.000000 0.020000 ( 0.018861)
0.020000 0.000000 0.020000 ( 0.019214)
0.020000 0.000000 0.020000 ( 0.011112)
0.020000 0.000000 0.020000 ( 0.010742)
0.020000 0.000000 0.020000 ( 0.018665)
0.020000 0.000000 0.020000 ( 0.019500)
0.020000 0.000000 0.020000 ( 0.018810)
0.020000 0.000000 0.020000 ( 0.011466)
0.010000 0.000000 0.010000 ( 0.013303)
0.020000 0.000000 0.020000 ( 0.018405)
0.020000 0.000000 0.020000 ( 0.018774)
0.020000 0.000000 0.020000 ( 0.018980)
0.020000 0.000000 0.020000 ( 0.021019)
0.010000 0.000000 0.010000 ( 0.011163)
0.010000 0.000000 0.010000 ( 0.010673)
0.020000 0.000000 0.020000 ( 0.019201)
0.010000 0.000000 0.010000 ( 0.019006)
0.020000 0.000000 0.020000 ( 0.019424)
0.010000 0.000000 0.010000 ( 0.010288)
0.020000 0.000000 0.020000 ( 0.018228)
0.020000 0.000000 0.020000 ( 0.019090)
0.020000 0.000000 0.020000 ( 0.019676)
0.020000 0.000000 0.020000 ( 0.012581)
0.010000 0.000000 0.010000 ( 0.010885)
- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10
Hors ligne
#1786 Le 15/08/2012, à 11:18
- grim7reaper
Re : /* Topic des codeurs [7] */
Ça bouffe 10% de moins chez moi (86% du CPU au lieu de 96-99 avant).
Hors ligne
#1787 Le 15/08/2012, à 11:23
- The Uploader
Re : /* Topic des codeurs [7] */
\o/
J'me demande comment faire du profiling, pour voir quels méthodes et quelles objets sont les plus gourmands sur l'ensemble du programme, au lieu d'insérer des Benchmark.measure(block) à des endroits précis où on pense déjà que ça prend pas mal de temps CPU...
- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10
Hors ligne
#1788 Le 15/08/2012, à 14:27
- samυncle
Re : /* Topic des codeurs [7] */
Je me suis amusé à coder un petit programme
#!/usr/python
# -*- coding: utf-8 -*-
# To run, just create a file with for example the name silvia.py and launch
# mass@carin:~/scripts> python silvia.py
import hashlib
# the path & the directory that have [0] >= '~'
strPath = "C:\Documents and Settings\john\Local Settings\Application Data\Google\Chrome\Application~dir1".encode("utf_16")[2:]
strsalt = "97486cAA225FE877C035cc0373236D51".decode("hex")
# add the salt
strkey = strPath + strsalt
strhash = hashlib.md5(strkey).hexdigest()
print "First hash:", strhash
# doing 10k hash
for i in range(0, 10000):
strhash = hashlib.md5(strhash.decode("hex")).hexdigest()
print "last hash:", strhash
Maintenant reste plus qu'a trouver la bonne chaine de caractères
Dernière modification par samυncle (Le 15/08/2012, à 14:28)
Hello world
Hors ligne
#1789 Le 15/08/2012, à 22:23
- The Uploader
Re : /* Topic des codeurs [7] */
Je comprends pas le bug de mon système expert. is_rule_valid rapport tout le temps false, alors qu'il ne devrait pas.
commit 163d8b057cdf685088bccb58d1ecafa459e5f82b
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Wed Aug 15 23:08:27 2012 +0200
A Point can now be substracted with another Point
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/lib/point.rb b/lib/point.rb
index 5e2a8da..c1eeaf8 100644
--- a/lib/point.rb
+++ b/lib/point.rb
@@ -22,6 +22,11 @@ module Lib
@x.to_i == other.x.to_i and @y.to_i == other.y.to_i
end
+ def -(other)
+ @x -= other.x
+ @y -= other.y
+ end
+
def normalize!(length_scale = 1)
@x = length_scale if @x > length_scale
@y = length_scale if @y > length_scale
commit 0a1d45f7f3441d611cde8cfe705f7b490fb509c8
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Wed Aug 15 23:08:09 2012 +0200
Bot: Begin to really use the ExpertSystem
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/MASWithTwoNests/bot.rb b/MASWithTwoNests/bot.rb
index c8a820b..8bd926d 100644
--- a/MASWithTwoNests/bot.rb
+++ b/MASWithTwoNests/bot.rb
@@ -67,7 +67,7 @@ module MASWithTwoNests
end
def update(tick, world)
- update_facts
+ update_facts(tick)
infer
act
move
@@ -88,10 +88,33 @@ module MASWithTwoNests
@expert_system.infer
end
- def update_facts
+ def update_facts(tick)
+ if @has_resource
+ else
+ @expert_system.set_fact_value(AgentFacts::NO_RESOURCE, true)
+ end
+
+ @update_time += tick.milliseconds
+ if @update_time > @direction_change_delay
+ @expert_system.set_fact_value(AgentFacts::CHANGE_DIRECTION_TIME, true)
+ @update_time = 0
+ end
+
+ if @seen_resource
+ @expert_system.set_fact_value(AgentFacts::SEE_RESOURCE, true)
+ end
+ end
+
+ def go_to_resource
+ @direction = @seen_resource.current_point - @target_point
+ @direction.normalize!
+ @seen_resource = nil
end
def act
+ @expert_system.inferred_facts.each do |fact|
+ puts fact.to_sym.to_s
+ end
end
def is_collided?(agent)
commit 222e2c27d462c867d47d8e871462e1c52b3dd40d
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Wed Aug 15 23:03:50 2012 +0200
Bugfixed FactBase, and faster ExpertSystem
The bug was to store keys in the FactBase#facts_values hash as references to
objects and trying to retrieve them with other references.
Naturally, it always returned nil.
Symbols are now used as keys.
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/ExpertSystem/expert_system.rb b/ExpertSystem/expert_system.rb
index 8e408a9..62129fb 100644
--- a/ExpertSystem/expert_system.rb
+++ b/ExpertSystem/expert_system.rb
@@ -16,22 +16,19 @@ module ExpertSystem
end
def add_fact(fact)
- @fact_base.facts_values.store(fact, false)
+ @fact_base.facts_values.store(fact.to_sym, false)
end
def set_fact_value(fact, value)
- @fact_base.facts_values[fact] = value if @fact_base.has_fact(fact)
+ @fact_base.facts_values[fact.to_sym] = value if @fact_base.has_fact(fact)
end
def get_fact_value(fact)
- return @fact_base.facts_values[fact] if @fact_base.has_fact(fact)
- return false
+ return @fact_base.facts_values[fact.to_sym] if @fact_base.has_fact(fact)
end
def reset_facts
- @fact_base.facts_values.each do |k,v|
- k[v] = false
- end
+ @fact_base.facts_values.clear
end
def add_rule(rule)
@@ -54,8 +51,8 @@ module ExpertSystem
def get_valid_rule
@rule_base.rules.each do |r|
- return r if is_rule_valid(r)
- end
+ return r if is_rule_valid(r)
+ end
return nil
end
diff --git a/ExpertSystem/fact.rb b/ExpertSystem/fact.rb
index b5bac33..510a933 100644
--- a/ExpertSystem/fact.rb
+++ b/ExpertSystem/fact.rb
@@ -8,5 +8,9 @@ module ExpertSystem
def ==(fact)
fact.label == @label
end
+
+ def to_sym
+ @label.to_sym
+ end
end
end
diff --git a/ExpertSystem/fact_base.rb b/ExpertSystem/fact_base.rb
index e5995d0..b2b1794 100644
--- a/ExpertSystem/fact_base.rb
+++ b/ExpertSystem/fact_base.rb
@@ -6,10 +6,7 @@ module ExpertSystem
end
def has_fact(fact)
- @facts_values.each do |f|
- return true if f == fact
- end
- return false
+ @facts_values[fact.to_sym]
end
end
end
diff --git a/ExpertSystem/rule.rb b/ExpertSystem/rule.rb
index 2572d97..6a54413 100644
--- a/ExpertSystem/rule.rb
+++ b/ExpertSystem/rule.rb
@@ -6,5 +6,9 @@ module ExpertSystem
@goal = goal
@premises = premises
end
+
+ def to_sym
+ @goal.label.to_sym
+ end
end
end
- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10
Hors ligne
#1790 Le 15/08/2012, à 22:23
- tshirtman
Re : /* Topic des codeurs [7] */
Bon, c'est un peu HS, mais bon… http://theoatmeal.com/blog/tesla_museum
Hors ligne
#1791 Le 16/08/2012, à 09:23
- Rolinh
Re : /* Topic des codeurs [7] */
Un projet qui compile si je passe le flag -j4 (à g++ ou clang++) mais qui ne compile pas sinon, vous trouvez aussi ça bizarre hein?
Hors ligne
#1792 Le 16/08/2012, à 09:25
- The Uploader
Re : /* Topic des codeurs [7] */
Et ça fonctionne ? O_o
- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10
Hors ligne
#1793 Le 16/08/2012, à 09:51
- tshirtman
Re : /* Topic des codeurs [7] */
Je suis pas du tout expert, mais je trouve ça bizarre oui… t'as quoi comme message si tu passe pas ça ?
Hors ligne
#1794 Le 16/08/2012, à 10:27
- Rolinh
Re : /* Topic des codeurs [7] */
Oui, ça semble fonctionner.
En fait ce qu'il se passe c'est que Bison génère des fichiers (*.yy.cc, *.tab.cc et *.tab.hh) et que, sans le -j4, je me retrouve avec un include qui appelle un fichier qui n'est pas encore généré et donc je me retrouve avec un file not found comme erreur. Avec le -j4, j'ai l'impression qu'il le génère à temps...
Dernière modification par Rolinh (Le 16/08/2012, à 10:28)
Hors ligne
#1795 Le 16/08/2012, à 11:23
- tshirtman
Re : /* Topic des codeurs [7] */
ah une race condition, cool (oupa
)
il manque surement un check de dépendance à un endroit, ou l'ordonnancement n'est pas bon
Hors ligne
#1796 Le 16/08/2012, à 11:28
- Rolinh
Re : /* Topic des codeurs [7] */
Ouep, oupa . Surtout quand faut trouver le problème parmi 50'000 lignes de code obscure...
Le truc bizarre, c'est que cela compile sans problèmes sur d'autres machines sous d'autres OS (OSX, OpenSuse 11.3).
Hors ligne
#1797 Le 17/08/2012, à 00:39
- tshirtman
Re : /* Topic des codeurs [7] */
Je me suis amusé à coder un petit programme
#!/usr/python # -*- coding: utf-8 -*- # To run, just create a file with for example the name silvia.py and launch # mass@carin:~/scripts> python silvia.py import hashlib # the path & the directory that have [0] >= '~' strPath = "C:\Documents and Settings\john\Local Settings\Application Data\Google\Chrome\Application~dir1".encode("utf_16")[2:] strsalt = "97486cAA225FE877C035cc0373236D51".decode("hex") # add the salt strkey = strPath + strsalt strhash = hashlib.md5(strkey).hexdigest() print "First hash:", strhash # doing 10k hash for i in range(0, 10000): strhash = hashlib.md5(strhash.decode("hex")).hexdigest() print "last hash:", strhash
Maintenant reste plus qu'a trouver la bonne chaine de caractères
Pour les mathématiciens qui passent dans le coins (oui le rouge on parle de toi ), vu qui md5 est un hash, on a des collisions à chaque passage non ? donc si on fait md5 récursivement 10 000 fois, un diminue sensiblement d'espace de résultat non ? enfin, c'est peut être pas du tout assez pour rendre une approche de bruteforce réaliste… sinon je pense que kaspersky aurait trouvé… et déterminer l'espace final de md5 possibles n'est peut être pas possible sans se taper les 9999 itérations sur tous les md5 possibles de base…
Hors ligne
#1798 Le 17/08/2012, à 15:11
- grim7reaper
Re : /* Topic des codeurs [7] */
Ouep, oupa
. Surtout quand faut trouver le problème parmi 50'000 lignes de code obscure...
Toujours sur ton terrible projet de compilateur ?
Hé merde, je vais replonger je le sens. La fois dernière, une méchante deadline m’en avait éloigné avant que je plonge trop dedans mais cette fois j’ai un peu de temps, donc je vais y rejouer et je crains le pire (ça va me faire comme pour NetHack :]).
Bon c’est juste LE jeu, j’ai une excuse ^^'
Hors ligne
#1799 Le 17/08/2012, à 15:23
- Rolinh
Re : /* Topic des codeurs [7] */
Toujours sur ton terrible projet de compilateur ?
Ouep. J'ai pris des petites vacances mais maintenant il faut bien que je m'y replonge. Ceci dit, le projet comporte aussi un interpréteur: le langage peut être compilé et exécuté par une machine virtuelle créée pour l'occasion (qu'il fait étendre, ce que je m'attelle à faire en ce moment) ET interprété (plus simple de ce côté).
C'est comme ça prenant Dwarf Fortress?
Hors ligne
#1800 Le 17/08/2012, à 15:41
- grim7reaper
Re : /* Topic des codeurs [7] */
Bah ça dépends du genre de jeu que tu aimes. Mais c’est vrai que celui là est de loin le jeu le plus abouti auquel j’ai joué.
Le niveau de détails est hallucinant. Ce que j’avais adoré dans NetHack c’est la devise « The DevTeam Thinks of Everything » (TDTTOE), mais là DF c’est le cran au-dessus, genre puissance 42.
Ça va faire 4-5 ans que j’en avait entendu parler (quand je me suis mis à NetHack), mais je me suis décidé à tester que récemment (début de cette année) pendant une courte période (projet, cours, toussa…). Là je vais retenter.
Comme Seb Sauvage le dit, le jeu a ses fans et les devs sont financé par les fans pour bosser à pleins temps dessus. De plus, les fans ont développés toute une suite d’outils autour du jeu. Et le coup de faire un processeur dans Minecraft c’était du réchauffé vu que ça avait aussi été fait dans DF :]
Bon, par contre le jeux est pas libre et l’auteur ne le souhaite pas. C’est un peu dommage, mais bon des alternatives libres existent mais elles sont encore très loin derrière… Et puis un port Linux existe, basé sur SDL (cette partie du port est open source par contre il me semble). Avant les gens devaient jouer via Wine…
Dernière modification par grim7reaper (Le 17/08/2012, à 15:43)
Hors ligne