#1826 Le 19/08/2012, à 04:59
- grim7reaper
Re : /* Topic des codeurs [7] */
Si quelqu'un a une idée...
gluErrorString, donc on ajoute -lGLU et ça passe :
$ gcc_debug -o petitfrancais petitfrancais.c -lglut -lGLEW -lGLU
Oui, je passe par gcc et pas g++, parce que ton code le seule truc de C++ qu’il a c’est l’extension du fichier hein…
Dernière modification par grim7reaper (Le 19/08/2012, à 05:01)
Hors ligne
#1827 Le 19/08/2012, à 09:47
- petifrancais
Re : /* Topic des codeurs [7] */
le code du tuto n'est que du C oui, je comptais plus tard le "c++iser" pour rendre mon code plus clair (et me sentir en terrain plus familier !).
Le code compile maintenant, mais plante à l'exécution.
j'ai mis plusieurs printf dans mon code pour repérer l'erreur :
./petitfrancais
Initialisation complete ?
GLUT initialisé
Contexte crée
Glew initialisé
INFO: OpenGL Version: 4.0.0 NVIDIA 295.40
Erreur de segmentation (core dumped)
Il plante juste avant le glClearColor..
Merci pour l'aide en tout cas, au moins le programme compile. Je regarderais plus en détail plus tard, mais pour l'instant je vois pas d'où ça peut venir, peut-être compiler les biblios à partir des sources et voir si le programme marche avec ?
Kubuntu 12.10 - KDE 4.9.5
Venez nous rejoindre sur le serveur minecraft zcraft.fr : http://forum.zcraft.fr/index.php
Hors ligne
#1828 Le 19/08/2012, à 10:03
- grim7reaper
Re : /* Topic des codeurs [7] */
Ha chez moi aussi hein.
Plus exactement, avec la carte Intel il se fait jeter par X :
X Error of failed request: BadRequest (invalid request code or no such operation)
Major opcode of failed request: 154 (GLX)
Minor opcode of failed request: 34 ()
Serial number of failed request: 34
Current serial number in output stream: 33
Avec la carte NVidia, il crash ouais :
INFO: OpenGL Version: 4.0.0 NVIDIA 302.17
A priori dans CreateVBO :
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x0000000000401c48 in CreateVBO () at petitfrancais.c:201
#2 0x0000000000401832 in Initialize (argc=1, argv=0x7fff3821b838) at petitfrancais.c:97
#3 0x0000000000401742 in main (argc=1, argv=0x7fff3821b838) at petitfrancais.c:65
(gdb) quit
Après d’où ça vient : la carte et/ou le driver supporte OpenGL 4.0 ?
Bug dans le driver Nvidia ?
… ?
Bonne question.
Édit : Résolu !
Remplace
glewInit();
par
glewExperimental = GL_TRUE;
glewInit();
Parce que
Experimental Drivers
GLEW obtains information on the supported extensions from the graphics driver. Experimental or pre-release drivers, however, might not report every available extension through the standard mechanism, in which case GLEW will report it unsupported. To circumvent this situation, the glewExperimental global switch can be turned on by setting it to GL_TRUE before calling glewInit(), which ensures that all extensions with valid entry points will be exposed.
Dernière modification par grim7reaper (Le 19/08/2012, à 10:12)
Hors ligne
#1829 Le 19/08/2012, à 10:28
- petifrancais
Re : /* Topic des codeurs [7] */
MERCI Grim ! Ca fonctionne à merveille, plus qu'à continuer le tuto.
Kubuntu 12.10 - KDE 4.9.5
Venez nous rejoindre sur le serveur minecraft zcraft.fr : http://forum.zcraft.fr/index.php
Hors ligne
#1830 Le 19/08/2012, à 21:27
- The Uploader
Re : /* Topic des codeurs [7] */
The Uploader a écrit :Pour ma part en jeux j'attends le remake ultra-fidèle de UFO : Enemy Unknown nommé XCOM : Enemy Unknown.
AfterMath, la série est absolument géniale. J'ai même récupérer un jeu de plateau si ça t'intéresse (XCOM Tactical, ça doit se trouver encore sur le net).
Ben AfterShock a été mon premier contact avec la série des UFO : After*, et il était super lent à charger, puis reprendre une planète est moins drôle que de la défendre, j'trouve.
Enfin j'ai la trilogie, mais j'ai pas touché aux autres, faute de temps.
Ton XCOM Tactical m'intéresse énormément.
Ton bot sert à quoi d'ailleurs ? Il joue à un jeu spécifique ou tu as un jeu avec un bot inclus ?
C'est un bot qui fait partie d'un exercice d'IA du prof que j'ai eu en dernière année :
http://www.nova-box.com/2009/10/epsi-cs … ts-part-2/
Ça se base sur des systèmes experts (mais sans logique floue ni rien de très avancé, juste des règles composées de faits, des actions, et les faits sont mis à jours à chaque update par le bot dans la méthode update_facts).
Ce que je fait, c'est la traduction en Ruby avec Rubygame et Rubygoo.
https://github.com/guybrush-threepwood/SMAFightRuby
D'ailleurs :
commit 1e3c79f025a113b5d72d45eb3cc16f162cb5068b
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Sun Aug 19 21:47:42 2012 +0200
Resource : redraw sprite when life amount changes
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/MASWithTwoNests/resource.rb b/MASWithTwoNests/resource.rb
index 01eea8c..4524e7d 100644
--- a/MASWithTwoNests/resource.rb
+++ b/MASWithTwoNests/resource.rb
@@ -23,17 +23,23 @@ module MASWithTwoNests
@image = Rubygame::Surface.new([World::RESOURCE_LIFE_RADIUS_COEFF * @life * 2, World::RESOURCE_LIFE_RADIUS_COEFF * @life * 2])
@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
+ draw_sprite
@rect.center = [rand * World::HEIGHT, rand * World::HEIGHT]
change_direction
end
+ def draw_sprite
+ @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
+ end
+
def decrease_life
@life = @life - World::RESOURCE_UPDATE_VALUE
+ draw_sprite
end
def increase_life
@life = @life + World::RESOURCE_UPDATE_VALUE
+ draw_sprite
end
def update(tick, world)
commit 3bf01571bbad7cebbd66df56455034d679187084
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Sun Aug 19 21:46:26 2012 +0200
Fully implemented Bot
But it still does nothing beside going away !
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/MASWithTwoNests/agent.rb b/MASWithTwoNests/agent.rb
index 58d871a..9ba6274 100644
--- a/MASWithTwoNests/agent.rb
+++ b/MASWithTwoNests/agent.rb
@@ -15,8 +15,11 @@ module MASWithTwoNests
@target_point = Point.new
@direction = Point.new
@dead = false
- end
-
+ end
+
+ def move
+ self.current_point = @target_point unless @world.is_out?(@target_point)
+ end
def current_point
Point.new(rect.center[0], rect.center[1])
end
diff --git a/MASWithTwoNests/bot.rb b/MASWithTwoNests/bot.rb
index ef6df9a..3ab9fc8 100644
--- a/MASWithTwoNests/bot.rb
+++ b/MASWithTwoNests/bot.rb
@@ -90,6 +90,36 @@ module MASWithTwoNests
@expert_system.add_rule(Rule.new(AgentFacts::GO_TO_RESOURCE,[ AgentFacts::NO_RESOURCE,
AgentFacts::SEE_RESOURCE,
AgentFacts::CHANGE_DIRECTION_TIME]))
+
+ @expert_system.add_rule(Rule.new(AgentFacts::TAKE_RESOURCE,[ AgentFacts::NO_RESOURCE,
+ AgentFacts::REACHED_RESOURCE]))
+
+ @expert_system.add_rule(Rule.new(AgentFacts::GO_HOME, [ AgentFacts::GOT_RESOURCE,
+ AgentFacts::SEEING_HOME]))
+
+ @expert_system.add_rule(Rule.new(AgentFacts::GO_TO_RESOURCE,[ AgentFacts::GOT_RESOURCE,
+ AgentFacts::SEE_RESOURCE,
+ AgentFacts::BIGGER_RESOURCE,
+ AgentFacts::NOT_SEEING_HOME,
+ AgentFacts::CHANGE_DIRECTION_TIME]))
+
+ @expert_system.add_rule(Rule.new(AgentFacts::CHANGE_DIRECTION,[ AgentFacts::GOT_RESOURCE,
+ AgentFacts::SEE_RESOURCE,
+ AgentFacts::SMALLER_RESOURCE,
+ AgentFacts::CHANGE_DIRECTION_TIME]))
+
+ @expert_system.add_rule(Rule.new(AgentFacts::PUT_DOWN_RESOURCE,[ AgentFacts::GOT_RESOURCE,
+ AgentFacts::REACHED_RESOURCE]))
+
+ @expert_system.add_rule(Rule.new(AgentFacts::PUT_DOWN_RESOURCE,[ AgentFacts::AT_HOME,
+ AgentFacts::GOT_RESOURCE ]))
+
+ @expert_system.add_rule(Rule.new(AgentFacts::CHANGE_DIRECTION,[ AgentFacts::NOTHING_SEEN,
+ AgentFacts::CHANGE_DIRECTION_TIME ]))
+
+ @expert_system.add_rule(Rule.new(AgentFacts::CHANGE_DIRECTION, [AgentFacts::TAKE_RESOURCE]))
+
+ @expert_system.add_rule(Rule.new(AgentFacts::CHANGE_DIRECTION, [AgentFacts::PUT_DOWN_RESOURCE]))
end
def infer
@@ -98,6 +128,7 @@ module MASWithTwoNests
def update_facts(tick)
if @has_resource
+ @expert_system.set_fact_value(AgentFacts::GOT_RESOURCE, true)
else
@expert_system.set_fact_value(AgentFacts::NO_RESOURCE, true)
end
@@ -110,6 +141,25 @@ module MASWithTwoNests
if @seen_resource
@expert_system.set_fact_value(AgentFacts::SEE_RESOURCE, true)
+ if @take_resource
+ if @seen_resource.life > @taken_resource.life
+ @expert_system.set_fact_value(AgentFacts::BIGGER_RESOURCE, true)
+ else
+ @expert_system.set_fact_value(AgentFacts::SMALLER_RESOURCE, true)
+ end
+ end
+ else
+ @expert_system.set_fact_value(AgentFacts::NOTHING_SEEN, true)
+ end
+
+ if @home
+ if is_collided?(@home)
+ @expert_system.set_fact_value(AgentFacts::AT_HOME, true)
+ else
+ @expert_system.set_fact_value(AgentFacts::NOT_SEEING_HOME, true)
+ end
+ else
+ @expert_system.set_fact_value(AgentFacts::NOT_SEEING_HOME, true)
end
end
@@ -121,6 +171,40 @@ module MASWithTwoNests
end
end
+ def take_resource
+ if @reached_resource
+ @reached_resource.decrease_life
+ @has_resource = true
+ @taken_resource = @reached_resource
+ @last_reached_resource = @reached_resource
+ @reached_resource = nil
+ end
+ @seen_resource = nil
+ end
+
+ def go_home
+ if (@home_position)
+ @direction = @home_position - @target_point
+ @direction.normalize!
+ end
+ end
+
+ def put_down_resource
+ if (@home)
+ @home.add_resource
+ @home = nil
+ else
+ if @reached_resource
+ @reached_resource.increase_life
+ @last_reached_resource = @reached_resource
+ @reached_resource = nil
+ @taken_resource = nil
+ end
+ end
+ @has_resource = false
+ @taken_resource = nil
+ end
+
def act
@expert_system.inferred_facts.each do |fact|
self.send(fact.action) if fact.action
@@ -135,7 +219,7 @@ module MASWithTwoNests
@target_point.x = current_point.x + @direction.x * real_speed * tick.seconds
@target_point.y = current_point.y + @direction.y * real_speed * tick.seconds
- self.current_point = @target_point unless @world.is_out?(@target_point)
+ super()
end
def is_collided?(agent)
diff --git a/MASWithTwoNests/resource.rb b/MASWithTwoNests/resource.rb
index 5a415bc..01eea8c 100644
--- a/MASWithTwoNests/resource.rb
+++ b/MASWithTwoNests/resource.rb
@@ -50,8 +50,7 @@ module MASWithTwoNests
@target_point.x += @direction.x * @speed * tick.seconds
@target_point.y += @direction.y * @speed * tick.seconds
-
- self.current_point = @target_point unless @world.is_out?(@target_point)
+ super()
end
end
end
commit a9fcf670041273db86ba8dbd3e675c3c4575b5c8
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Sun Aug 19 20:01:21 2012 +0200
Bugfix: Point#- wasn't returning a Point instance
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/lib/point.rb b/lib/point.rb
index c1eeaf8..b173ac5 100644
--- a/lib/point.rb
+++ b/lib/point.rb
@@ -25,6 +25,7 @@ module Lib
def -(other)
@x -= other.x
@y -= other.y
+ return self
end
def normalize!(length_scale = 1)
commit 077829878bdf608aecdd8cdae4530a70c35bd960
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Sun Aug 19 20:01:07 2012 +0200
Moving bots
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/MASWithTwoNests/agent.rb b/MASWithTwoNests/agent.rb
index 8289332..58d871a 100644
--- a/MASWithTwoNests/agent.rb
+++ b/MASWithTwoNests/agent.rb
@@ -17,10 +17,6 @@ module MASWithTwoNests
@dead = false
end
- def move
- self.current_point = @target_point unless @world.is_out?(@target_point)
- end
-
def current_point
Point.new(rect.center[0], rect.center[1])
end
diff --git a/MASWithTwoNests/bot.rb b/MASWithTwoNests/bot.rb
index ea8770f..ef6df9a 100644
--- a/MASWithTwoNests/bot.rb
+++ b/MASWithTwoNests/bot.rb
@@ -78,7 +78,7 @@ module MASWithTwoNests
infer
act
draw_sprite
- move
+ move(tick)
@reached_resource = nil
@home = nil
@@ -127,6 +127,17 @@ module MASWithTwoNests
end
end
+ def move(tick)
+ real_speed = @speed
+ if(@has_resource)
+ real_speed *= World::BOT_WITH_RESOURCE_SPEED_COEFF
+ end
+
+ @target_point.x = current_point.x + @direction.x * real_speed * tick.seconds
+ @target_point.y = current_point.y + @direction.y * real_speed * tick.seconds
+ self.current_point = @target_point unless @world.is_out?(@target_point)
+ end
+
def is_collided?(agent)
collide_sprite?(agent)
end
diff --git a/MASWithTwoNests/resource.rb b/MASWithTwoNests/resource.rb
index 7a81d6c..5a415bc 100644
--- a/MASWithTwoNests/resource.rb
+++ b/MASWithTwoNests/resource.rb
@@ -38,7 +38,10 @@ module MASWithTwoNests
def update(tick, world)
@dead = true if @life <= 0
+ move(tick, world)
+ end
+ def move(tick, world)
@update_time += tick.milliseconds
if @update_time > @move_delay or world.is_out?(@target_point)
change_direction
@@ -48,7 +51,7 @@ module MASWithTwoNests
@target_point.x += @direction.x * @speed * tick.seconds
@target_point.y += @direction.y * @speed * tick.seconds
- move
+ self.current_point = @target_point unless @world.is_out?(@target_point)
end
end
end
commit fc12c9e8f0b8b490b71d4f021fa5816423105b81
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Fri Aug 17 20:01:06 2012 +0200
Faster Bot#draw_sprite, called on each update
Because a change of color happens when the Bot has a Resource
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/MASWithTwoNests/bot.rb b/MASWithTwoNests/bot.rb
index 40cc022..ea8770f 100644
--- a/MASWithTwoNests/bot.rb
+++ b/MASWithTwoNests/bot.rb
@@ -45,6 +45,7 @@ module MASWithTwoNests
resource_color_ary[i] += 0x55 #0X228822
end
@resource_color = Rubygame::Color::ColorRGB.new([resource_color_ary[0], resource_color_ary[1], resource_color_ary[2]])
+ @current_color = nil
init_expert_system
init_sprite
@@ -53,16 +54,22 @@ module MASWithTwoNests
end
def init_sprite
- @image = Rubygame::Surface.new([ @radius, @radius ])
+ @image = Rubygame::Surface.new([@radius, @radius])
@image.set_colorkey([0, 0, 0])
@rect = @image.make_rect
end
def draw_sprite
- if (@has_resource)
- @image.draw_circle_s(@rect.center, @radius, @resource_color)
+ if @has_resource
+ if @current_color != @resource_color
+ @image.draw_circle_s(@rect.center, @radius, @resource_color)
+ @current_color = @resource_color
+ end
else
- @image.draw_circle_s(@rect.center, @radius, @color)
+ if @current_color != @color
+ @image.draw_circle_s(@rect.center, @radius, @color)
+ @curent_color = @color
+ end
end
end
@@ -70,6 +77,7 @@ module MASWithTwoNests
update_facts(tick)
infer
act
+ draw_sprite
move
@reached_resource = nil
@@ -77,7 +85,7 @@ module MASWithTwoNests
end
def init_expert_system
- @expert_system = ExpertSystem::ExpertSystem.new()
+ @expert_system = ExpertSystem::ExpertSystem.new
@expert_system.add_rule(Rule.new(AgentFacts::GO_TO_RESOURCE,[ AgentFacts::NO_RESOURCE,
AgentFacts::SEE_RESOURCE,
commit 7551928db8e82b3af00a2b369fbef632eee9d4e1
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Fri Aug 17 19:59:19 2012 +0200
Facts can have an action (symbol for a Bot method, called by Bot#act)
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/ExpertSystem/fact.rb b/ExpertSystem/fact.rb
index 510a933..3a30abc 100644
--- a/ExpertSystem/fact.rb
+++ b/ExpertSystem/fact.rb
@@ -1,8 +1,10 @@
module ExpertSystem
class Fact
attr_reader :label
- def initialize(label)
+ attr_reader :action
+ def initialize(label, action = nil)
@label = label
+ @action = action
end
def ==(fact)
diff --git a/MASWithTwoNests/agent_facts.rb b/MASWithTwoNests/agent_facts.rb
index 84f53b0..8ed26fd 100644
--- a/MASWithTwoNests/agent_facts.rb
+++ b/MASWithTwoNests/agent_facts.rb
@@ -16,9 +16,10 @@ module MASWithTwoNests
NOT_SEEING_HOME = Fact.new("Not seeing home")
GO_HOME = Fact.new("Go home")
AT_HOME = Fact.new("At home")
- CHANGE_DIRECTION = Fact.new("Changing direction")
- GO_TO_RESOURCE = Fact.new("Going to resource")
- TAKE_RESOURCE = Fact.new("Taking Resource.")
- PUT_DOWN_RESOURCE = Fact.new("Putting down Resource.")
+
+ CHANGE_DIRECTION = Fact.new("Changing direction", :change_direction)
+ GO_TO_RESOURCE = Fact.new("Going to resource", :go_to_resource)
+ TAKE_RESOURCE = Fact.new("Taking Resource.", :take_resource)
+ PUT_DOWN_RESOURCE = Fact.new("Putting down Resource.", :put_down_resource)
end
end
diff --git a/MASWithTwoNests/bot.rb b/MASWithTwoNests/bot.rb
index 8bd926d..40cc022 100644
--- a/MASWithTwoNests/bot.rb
+++ b/MASWithTwoNests/bot.rb
@@ -106,14 +106,16 @@ module MASWithTwoNests
end
def go_to_resource
- @direction = @seen_resource.current_point - @target_point
- @direction.normalize!
- @seen_resource = nil
+ if @seen_resource
+ @direction = @seen_resource.current_point - @target_point
+ @direction.normalize!
+ @seen_resource = nil
+ end
end
def act
@expert_system.inferred_facts.each do |fact|
- puts fact.to_sym.to_s
+ self.send(fact.action) if fact.action
end
end
commit 7d6c712be745e2920276d1fd59045e384dd0d689
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Fri Aug 17 19:58:27 2012 +0200
More SOLID ExpertSystem and FactBase, fixed is_rule_valid in the process
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/ExpertSystem/expert_system.rb b/ExpertSystem/expert_system.rb
index 62129fb..e0fbb77 100644
--- a/ExpertSystem/expert_system.rb
+++ b/ExpertSystem/expert_system.rb
@@ -7,7 +7,6 @@ require 'fact'
module ExpertSystem
class ExpertSystem
attr_reader :fact_base
- attr_reader :rule_base
attr_reader :inferred_facts
def initialize
@fact_base = FactBase.new
@@ -15,38 +14,40 @@ module ExpertSystem
@inferred_facts = []
end
- def add_fact(fact)
- @fact_base.facts_values.store(fact.to_sym, false)
- end
+ def add_rule(rule)
+ @fact_base.add_fact(rule) if not @fact_base.has_fact(rule)
- def set_fact_value(fact, value)
- @fact_base.facts_values[fact.to_sym] = value if @fact_base.has_fact(fact)
- end
+ rule.premises.each do |p|
+ @fact_base.add_fact(p) if not @fact_base.has_fact(p)
+ end
- def get_fact_value(fact)
- return @fact_base.facts_values[fact.to_sym] if @fact_base.has_fact(fact)
+ @rule_base.add_rule(rule)
end
- def reset_facts
- @fact_base.facts_values.clear
+ def infer
+ clear_inferred_facts
+
+ begin
+ valid_rule = get_valid_rule
+ if valid_rule
+ @fact_base.set_fact_value(valid_rule.goal, true)
+ @inferred_facts << valid_rule.goal
+ end
+ end while valid_rule != nil
end
- def add_rule(rule)
- add_fact(rule) if not @fact_base.has_fact(rule)
+ def set_fact_value(fact, value)
+ @fact_base.set_fact_value(fact, value)
+ end
- rule.premises.each do |p|
- add_fact(p) if not @fact_base.has_fact(p)
- end
- @rule_base.add_rule(rule)
- end
+ private
def is_rule_valid(rule)
- return false if get_fact_value(rule.goal)
+ return false if @fact_base.get_fact_value(rule.goal)
rule.premises.each do |p|
- return false if not get_fact_value(p)
+ return @fact_base.get_fact_value(p)
end
- return true
end
def get_valid_rule
@@ -59,17 +60,5 @@ module ExpertSystem
def clear_inferred_facts
@inferred_facts = []
end
-
- def infer
- clear_inferred_facts
-
- begin
- valid_rule = get_valid_rule
- if valid_rule
- set_fact_value(valid_rule.goal, true)
- @inferred_facts << valid_rule.goal
- end
- end while valid_rule != nil
- end
end
end
diff --git a/ExpertSystem/fact_base.rb b/ExpertSystem/fact_base.rb
index b2b1794..7e25e33 100644
--- a/ExpertSystem/fact_base.rb
+++ b/ExpertSystem/fact_base.rb
@@ -1,12 +1,27 @@
module ExpertSystem
class FactBase
- attr_accessor :facts_values
def initialize
@facts_values = {}
end
def has_fact(fact)
+ @facts_values.keys.include?(fact.to_sym)
+ end
+
+ def add_fact(fact)
+ @facts_values.store(fact.to_sym, false)
+ end
+
+ def set_fact_value(fact, value)
+ @facts_values[fact.to_sym] = value
+ end
+
+ def get_fact_value(fact)
@facts_values[fact.to_sym]
end
+
+ def reset_facts
+ @facts_values.clear
+ end
end
end
commit 449477ca3a5b2a0ee7080c368efa33cdac57366e
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Fri Aug 17 19:55:45 2012 +0200
Faster cleaning of dead agents
Only resources can die.
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
diff --git a/MASWithTwoNests/world.rb b/MASWithTwoNests/world.rb
index bb05337..4f6c9c1 100644
--- a/MASWithTwoNests/world.rb
+++ b/MASWithTwoNests/world.rb
@@ -48,10 +48,12 @@ module MASWithTwoNests
@background = Rubygame::Surface.new([WIDTH, HEIGHT])
@agents = Rubygame::Sprites::Group.new
@bot_teams = []
+ @resources = []
Rubygame::Sprites::UpdateGroup.extend_object @agents
RESOURCE_COUNT.times do
resource = Resource.new(self, RESOURCE_START_LIFE, RESOURCE_MOVE_DELAY * rand, RESOURCE_MOVE_SPEED * rand)
resource.target_point = Point.new(rand * WIDTH, rand * HEIGHT)
+ @resources << resource
@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)
@@ -63,13 +65,22 @@ module MASWithTwoNests
@agents.undraw @screen, @background
@agents.update(tick, self)
@agents.draw @screen
- clean_dead_agents
+ clean_dead_resources
check_collisions
end
- def clean_dead_agents
- @agents.each do |a|
- @agents.delete(a) if a.dead
+ 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 clean_dead_resources
+ @resources.each do |r|
+ if r.dead
+ @agents.delete(r)
+ @resources.delete(r)
+ end
end
end
@@ -89,12 +100,6 @@ module MASWithTwoNests
end
end
- 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)
(le bot semble faire les actions, mais il va toujours dans la même direction. @seen_resource / @reached_resource, etc... sont pourtant bien affectés des références à des objets par on_collide et on_perception mais lors de l'action ils sont toujours nil)
Ça me fait penser à une race condition, mais sans thread... (et pas logique vu que si avant l'appelle de l'action @seen_resource est nil, le fait correspondant est faux, la règle est fausse, et l'action ne devrait pas être appellée parce qu'elle ne ferait pas partie des faits inférés par le système expert...)
En fait change_direction (direction au hasard) est appelé par le constructeur, mais après ça, vu qu'aucune action n'est véritablement effective (par exemple : @seen_resource est vérifié par go_to_resource. Si c'est nil, rien ne se passe), elle ne change pas.
W. T. F.
Dernière modification par The Uploader (Le 19/08/2012, à 22:24)
- 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
#1831 Le 20/08/2012, à 07:50
- The Uploader
Re : /* Topic des codeurs [7] */
The Uploader a écrit :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
).
Testé à nouveau sur la même machine : ça tourne très bien, ça prend au pire 100% l'un des 4 cores.
CPU :
-> lscpu
Architecture: i686
mode(s) opératoire(s) des microprocesseurs :32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) par cœur : 2
Cœur(s) par socket : 2
Socket(s) de microprocesseur :1
Identifiant constructeur :GenuineIntel
Famille de microprocesseur :6
Modèle : 28
Version : 10
Vitesse du microprocesseur en MHz :1800.149
BogoMIPS: 3600.15
cache L1d : 24K
cache L1i : 32K
cache L2 : 512K
-> cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 28
model name : Intel(R) Atom(TM) CPU D525 @ 1.80GHz
stepping : 10
cpu MHz : 1800.149
cache size : 512 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl tm2 ssse3 cx16 xtpr pdcm movbe lahf_lm dtherm
bogomips : 3600.29
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 28
model name : Intel(R) Atom(TM) CPU D525 @ 1.80GHz
stepping : 10
cpu MHz : 1800.149
cache size : 512 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 2
apicid : 1
initial apicid : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl tm2 ssse3 cx16 xtpr pdcm movbe lahf_lm dtherm
bogomips : 3600.11
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 2
vendor_id : GenuineIntel
cpu family : 6
model : 28
model name : Intel(R) Atom(TM) CPU D525 @ 1.80GHz
stepping : 10
cpu MHz : 1800.149
cache size : 512 KB
physical id : 0
siblings : 4
core id : 1
cpu cores : 2
apicid : 2
initial apicid : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl tm2 ssse3 cx16 xtpr pdcm movbe lahf_lm dtherm
bogomips : 3600.13
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 28
model name : Intel(R) Atom(TM) CPU D525 @ 1.80GHz
stepping : 10
cpu MHz : 1800.149
cache size : 512 KB
physical id : 0
siblings : 4
core id : 1
cpu cores : 2
apicid : 3
initial apicid : 3
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl tm2 ssse3 cx16 xtpr pdcm movbe lahf_lm dtherm
bogomips : 3600.15
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
CG :
-> lspci | grep "VGA"
00:02.0 VGA compatible controller: Intel Corporation N10 Family Integrated Graphics Controller (rev 02)
Comme quoi quelques optimisations peuvent faire toute la différence !
Par contre, je n'ai pas testé USF.
Dernière modification par The Uploader (Le 20/08/2012, à 07:53)
- 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
#1832 Le 20/08/2012, à 11:27
- tshirtman
Re : /* Topic des codeurs [7] */
C'est sur, quand t'identifie un goulot d'étranglement, tu peut souvent facilement augmenter radicalement les prefs. Ce qui est plus embétant, c'est quand tu les as tous éliminé et que c'est encore un peu trop lent, ça veux dire qu'il faut revoir l'archi complètement, et ça, c'est pas cool ^^.
Hors ligne
#1833 Le 22/08/2012, à 12:52
- The Uploader
Re : /* Topic des codeurs [7] */
Yép.
------
Tiens, il n'y a même plus de warmux/wormux.org.
Mais il y a un mirroir : http://sourceforge.net/projects/warmux.mirror/files/
- 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
#1834 Le 22/08/2012, à 20:07
- The Uploader
Re : /* Topic des codeurs [7] */
' dormez les codeurs ?
commit fc65766076a16fbc9bbaf8ad2b10b2f7aded5eb2 (HEAD, refs/heads/master)
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Wed Aug 22 21:05:22 2012 +0200
Bot: can StealResource, DropResource, drop an agent
Droping an agent adds an agent into the world
(such as a pheromone - which would be a new type of agent)
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
---
MASWithTwoNests/bot.rb | 18 +++++++++++++++++-
MASWithTwoNests/world.rb | 6 +++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/MASWithTwoNests/bot.rb b/MASWithTwoNests/bot.rb
index 3ab9fc8..9ecdbd7 100644
--- a/MASWithTwoNests/bot.rb
+++ b/MASWithTwoNests/bot.rb
@@ -12,11 +12,13 @@ require 'resource'
require 'world'
require 'rubygame'
require 'bot_home'
+require 'resource'
module MASWithTwoNests
class Bot < Agent
attr_reader :home_position
attr_reader :team_id
+ attr_accessor :has_resource
def initialize(world, team_id, color, radius, speed, direction_change_delay, perception_radius)
super(world)
@team_id = team_id
@@ -207,7 +209,7 @@ module MASWithTwoNests
def act
@expert_system.inferred_facts.each do |fact|
- self.send(fact.action) if fact.action
+ send(fact.action) if fact.action
end
end
@@ -222,6 +224,20 @@ module MASWithTwoNests
super()
end
+ def steal_resource(bot)
+ bot.has_resource = false
+ @has_resource = true
+ end
+
+ def drop_resource
+ drop(Resource.new(@world, World::RESOURCE_UPDATE_VALUE, World::RESOURCE_MOVE_DELAY, World::RESOURCE_MOVE_SPEED)) if @has_resource
+ end
+
+ def drop(agent)
+ agent.target_point = Point.new(@target_point.x, @target_point.y)
+ @world.add_agent(agent)
+ end
+
def is_collided?(agent)
collide_sprite?(agent)
end
diff --git a/MASWithTwoNests/world.rb b/MASWithTwoNests/world.rb
index 4f6c9c1..da267f2 100644
--- a/MASWithTwoNests/world.rb
+++ b/MASWithTwoNests/world.rb
@@ -15,8 +15,8 @@ module MASWithTwoNests
class World
attr_accessor :home_getting_bigger
attr_accessor :bot_start_from_home
- attr_accessor :agents
attr_accessor :screen
+ attr_reader :agents
WIDTH = 600
HEIGHT = 600
@@ -60,6 +60,10 @@ module MASWithTwoNests
@bot_teams << bot_team
end
+ def add_agent(agent)
+ @agents << agent if agent.class.ancestors.include?(Agent)
+ end
+
def update(tick)
@background.blit @screen, [0, 0]
@agents.undraw @screen, @background
commit 7d158c80bdbecc026308312fc23f98f3a9a65f7d
Author: Maximilien Noal <mnoal@epsi.fr>
Date: Wed Aug 22 21:04:03 2012 +0200
BotHome : redraw sprite when Resource amount changes
The sprite can be bigger only if "home getting bigger" is checked
Signed-off-by: Maximilien Noal <mnoal@epsi.fr>
---
MASWithTwoNests/bot_home.rb | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/MASWithTwoNests/bot_home.rb b/MASWithTwoNests/bot_home.rb
index 49b7512..bbe18e2 100644
--- a/MASWithTwoNests/bot_home.rb
+++ b/MASWithTwoNests/bot_home.rb
@@ -16,18 +16,36 @@ module MASWithTwoNests
@resource_count = 0
@team_id = team_id
@color = color
- @image = Rubygame::Surface.new([World::HOME_RADIUS * 2, World::HOME_RADIUS * 2])
- @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 = [rand * World::HEIGHT, rand * World::HEIGHT]
+ @radius = nil
+ @center = [rand * World::HEIGHT, rand * World::HEIGHT]
+ draw_sprite(world)
end
def update(tick, world)
+ draw_sprite(world)
end
def add_resource
@resource_count += 1
end
+
+ private
+
+ def draw_sprite(world)
+ new_radius = nil
+ if world.home_getting_bigger
+ new_radius = World::HOME_RADIUS + @resource_count
+ else
+ new_radius = World::HOME_RADIUS
+ end
+ if new_radius != @radius or @radius == nil
+ @radius = new_radius
+ @image = Rubygame::Surface.new([@radius * 2, @radius * 2])
+ @rect = @image.make_rect
+ @image.set_colorkey([0, 0, 0])
+ @image.draw_circle_s(@rect.center, @radius, @color)
+ @rect.center = @center
+ end
+ 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
#1835 Le 22/08/2012, à 22:38
- Rolinh
Re : /* Topic des codeurs [7] */
' dormez les codeurs ?
Du tout.
En train de peaufiner mon projet compilateur/interprète (extension d'un langage informatique).
Je suis retombé sur ce chef d’œuvre, qui m'avait bien fait rire à première lecture:
if (0 && dejaPresentAuSommet)
// code
Sûrement un moyen de commenter/faire des tests...
*Don't dig too deep into this code...*
Dernière modification par Rolinh (Le 22/08/2012, à 22:38)
Hors ligne
#1836 Le 22/08/2012, à 23:01
- tshirtman
Re : /* Topic des codeurs [7] */
Moi j'essaye d'ajouter la gestion des varargs à notre wrapper python de java, c'est quelque chose ^^.
Hors ligne
#1837 Le 23/08/2012, à 20:40
Hors ligne
#1838 Le 24/08/2012, à 15:29
- The Uploader
Re : /* Topic des codeurs [7] */
(bon en fait c'est super sympa YUI 3, mais à travers CoffeeScript...)
- 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
#1839 Le 24/08/2012, à 21:20
- grim7reaper
Re : /* Topic des codeurs [7] */
Tiens HP fait de la suppression de post…
Du coup tshirtman semble balancer un lien dans le vent, spas très sympa ^^'
Dernière modification par grim7reaper (Le 24/08/2012, à 21:23)
Hors ligne
#1840 Le 24/08/2012, à 21:48
- tshirtman
Re : /* Topic des codeurs [7] */
Oui, c'est une habitude chez lui
Hors ligne
#1841 Le 24/08/2012, à 22:24
- The Uploader
Re : /* Topic des codeurs [7] */
C'est nul comme habitude.
- 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
#1842 Le 25/08/2012, à 07:20
- Mindiell
Re : /* Topic des codeurs [7] */
Retour de vacances,
Ton XCOM Tactical m'intéresse énormément.
Tu l'as trouvé ou je te le mets quelque part ?
C'est un bot qui fait partie d'un exercice d'IA du prof que j'ai eu en dernière année
Ok, marrant. J'y jetterai p'tet un oeil... Merci
Hors ligne
#1843 Le 25/08/2012, à 23:30
- Dr Le Rouge
Re : /* Topic des codeurs [7] */
Je commence à voir le bout de mon projet lié au vote électronique (rien à voir avec cryptheory ^^) \o/ J'ai mis la doxygen en ligne sur mon site.
edit : d'ailleurs, la dernière version de doxygen (pas celle des dépôts de Precise) supporte le MarkDown ; c'est fort pratique.
Dernière modification par Dr Le Rouge (Le 25/08/2012, à 23:33)
C'est deux suites de Cauchy qui veulent aller à la soirée 'no limit'. Hélas, à l'entrée le videur leur dit : "désolé, c'est complet !".
mon site perso (π²/6.fr) et mon blog
Hors ligne
#1844 Le 25/08/2012, à 23:59
- PJSimply
Re : /* Topic des codeurs [7] */
C'est toujours le projet pour choper les quotes?
Ça me tente bien Python ou shell?
python serait plus efficace mais bon
Hors ligne
#1845 Le 26/08/2012, à 01:45
- Pylades
Re : /* Topic des codeurs [7] */
Sinon, j’ai fait quelques commits made in Russia, dont un +473/−478.
(Bon, j’ai oublié d’installer PyGTK donc je n’ai rien fait sur Hortus…)
“Any if-statement is a goto. As are all structured loops.
“And sometimes structure is good. When it’s good, you should use it.
“And sometimes structure is _bad_, and gets into the way, and using a goto is just much clearer.”
Linus Torvalds – 12 janvier 2003
Hors ligne
#1846 Le 26/08/2012, à 04:57
- grim7reaper
Re : /* Topic des codeurs [7] */
(rien à voir avec cryptheory ^^)
\o/, ma proposition a été retenue ^^
Bon sinon j’irais jeter un œil à ton site de dissident plus tard.
C'est toujours le projet pour choper les quotes?
Ça me tente bienPython ou shell?
python serait plus efficace mais bon
Yep, toujours en cours. Pour le langage pas de contraintes donc tu fais comme tu le sens.
(Bon, j’ai oublié d’installer PyGTK donc je n’ai rien fait sur Hortus…)
Bah j’ai envie de dire que t’es pas le seul. Hortus a pas bouger d’une ligne depuis la fin du concours.
Ha si, il y a quelque semaines j’ai trashé ton A* buggé pour en refaire un from scratch
Il fonctionne beaucoup mieux (au moins y’a plus de grosses téléportations aléatoires) mais reste 2-3 bugs, à part ça absolument rien de neuf.
Faudrait quand même qu’on finisse le jeu avant de nous-même passer l’arme à gauche hein…
Hors ligne
#1847 Le 26/08/2012, à 10:27
- Dr Le Rouge
Re : /* Topic des codeurs [7] */
Bon sinon j’irais jeter un œil à ton site de dissident plus tard.
Je suis bloqué ? Rooooh, la classe
C'est deux suites de Cauchy qui veulent aller à la soirée 'no limit'. Hélas, à l'entrée le videur leur dit : "désolé, c'est complet !".
mon site perso (π²/6.fr) et mon blog
Hors ligne
#1848 Le 26/08/2012, à 12:04
- PJSimply
Re : /* Topic des codeurs [7] */
@ grim7reaper
Pour VMD vite fait :
#! /bin/bash
# lecture des arguments
while [ $# -gt 0 ]
do
case "$1" in
-c) cat=$2; shift;;
-a) a=1 ;;
--) shift; break;;
-*)
echo >&2 \
"usage: $0 [-a pour une quote aléatoire] [-c pour choisir la catégorie] catégorie"
exit 1;;
*) break;;
esac
shift;
done;
# dans le cas ou c'est pas aléatoire
if [ ! $a ]
then
quotes=`GET www.viedemerde.fr/$cat | grep 'post article' | sed 's:<a href=\"/[a-z]*/[0-9]*\" class="fmllink">::g' | sed 's:<div class=\"post article\" id=\"[0-9]*\">::g' | sed 's:<p>::g' | sed 's:</a>::g' | cut -d '<' -f1 | sed 's:":":g'`
else
if [ $cat ]
then c_test=" grep $cat "
fi;
while [ "$quotes" == "" ]
do quotes=`GET www.viedemerde.fr/aleatoire | grep 'post article' | $c_test | sed 's:<a href=\"/[a-z]*/[0-9]*\" class="fmllink">::g' | sed 's:<div class=\"post article\" id=\"[0-9]*\">::g' | sed 's:<p>::g' | sed 's:</a>::g' | cut -d '<' -f1 | sed 's:":":g' `
done
fi;
echo $quotes | sed "s:VDM:VDM|:g" | cut -d "|" -f1
# je ne sais pas pourquoi quand je mettais ça à la suite de l'expression moche au dessus ça ne fonctionnait pas
C'est pas très joli mais je vais l'améliorer.
Dernière modification par PJSimply (Le 26/08/2012, à 12:07)
Hors ligne
#1849 Le 26/08/2012, à 12:41
- grim7reaper
Re : /* Topic des codeurs [7] */
grim7reaper a écrit :Bon sinon j’irais jeter un œil à ton site de dissident plus tard.
Je suis bloqué ? Rooooh, la classe
Yep.
T’aurais appelé ton site Le Rouge tu serais ptêtre passé ^^
@PJSimply : l’option pour l’aléatoire fonctionne pas (y’a rien qui sort, le script se termine pas). Ça vient peut-être de moi, mais les autres sont OK donc ça serait bizarre.
Hors ligne
#1850 Le 26/08/2012, à 13:25
- PJSimply
Re : /* Topic des codeurs [7] */
@ grim7reaper non ça plante chez moi aussi j'ai du me tromper. C'est corrigé :
#! /bin/bash
url='http://www.viedemerde.fr/'
a=""
cflag=""
while [ $# -gt 0 ]
do
case "$1" in
-c) cat=$2; shift;;
-a) a=1 ;;
--) shift; break;;
-*)
echo >&2 \
"usage: $0 [-a pour une quote aléatoire] [-c pour choisir la catégorie] catégorie"
exit 1;;
*) break;;
esac
shift;
done;
if [ ! $a ]
then
quotes=`GET www.viedemerde.fr/$cat | grep 'post article' | sed 's:<a href=\"/[a-z]*/[0-9]*\" class="fmllink">::g' | sed 's:<div class=\"post article\" id=\"[0-9]*\">::g' | sed 's:<p>::g' | sed 's:</a>::g' | cut -d '<' -f1 | sed 's:":":g'`
else
if [ $cat ]
then
while [ "$quotes" == "" ]
do quotes=`GET www.viedemerde.fr/aleatoire | grep 'post article' | grep $cat | sed 's:<a href=\"/[a-z]*/[0-9]*\" class="fmllink">::g' | sed 's:<div class=\"post article\" id=\"[0-9]*\">::g' | sed 's:<p>::g' | sed 's:</a>::g' | cut -d '<' -f1 | sed 's:":":g' `
done
else
quotes=`GET www.viedemerde.fr/aleatoire | grep 'post article' | sed 's:<a href=\"/[a-z]*/[0-9]*\" class="fmllink">::g' | sed 's:<div class=\"post article\" id=\"[0-9]*\">::g' | sed 's:<p>::g' | sed 's:</a>::g' | cut -d '<' -f1 | sed 's:":":g' `
fi;
fi;
echo $quotes | sed "s:VDM:VDM|:g" | cut -d "|" -f1
Hors ligne