Small Hangup in Corewars Evolver

Corewars is a neat little programming game where players develop
assembly like programs to battle in virtual memory. My evolver uses
selective pressure to evolve warriors through variance.

The problem is that currently the breed method is producing several
generations of grand parents instead of several parallel first
generation children.

Code:

module Utilities
class Line
attr_accessor :rawtext, :command, :number1, :number2
def initialize(rawtextsource)
rawtext = []
rawtext = rawtextsource.split(//)
@command = rawtext[0…2].join
@number1 = rawtext[4]
@number2 = rawtext[7]
end
end
class Warrior
attr_accessor :location, :lines, :filename, :rawtext,
:instructionset
def initialize(location)
code = File.open(location, ‘r’)
@filename = location
@rawtext = code.readlines()
@lines = []
for line in rawtext
@lines << Line.new(line)
@instructionset =
File.open("/home/brad/NetBeansProjects/BGEvolver/lib/instructionset.txt",
‘r’).readlines.map {|x| x.chomp}
end
end
def updateraw
counter = 0
while counter < self.rawtext.length
self.rawtext[counter] = self.lines[counter].command + " " +
self.lines[counter].number1 + “, " + self.lines[counter].number2 + “\n”
counter += 1
end
return self
end
def mutate(chancecommand, chancenumber1, chancenumber2)
for line in self.lines
dice = rand(100)
line.command =
self.instructionset[rand(self.instructionset.length)] if
Array(0…chancecommand).include?(dice)
line.number1 = (line.number1.to_i + rand(10)).to_s if
Array(20…(20+chancenumber1 / 2)).include?(dice)
line.number1 = (line.number1.to_i + rand(10) * -1).to_s if
Array(30…(30+chancenumber1 / 2)).include?(dice)
line.number2 = (line.number2.to_i + rand(10)).to_s if
Array(40…(40+chancenumber2 / 2)).include?(dice)
line.number2 = (line.number2.to_i + rand(10) * -1).to_s if
Array(50…(50+chancenumber2 / 2)).include?(dice)
end
self.updateraw
end
def save(location)
self.updateraw
File.open(location, ‘w’).puts(self.rawtext)
end
def breed(offspring, chancecommand, chancenumber1, chancenumber2,
destfolder, botidcounter)
counter = 0
while counter < offspring
tmp = self.dup
tmp.mutate(chancecommand, chancenumber1,
chancenumber2).save(destfolder+”/"+((botidcounter += 1).to_s)+".RED")
counter += 1
end
return botidcounter
end
end
end

and also main.rb:

require “/home/brad/NetBeansProjects/BGEvolver/lib/utilities.rb”
include Utilities

nop =
Warrior.new("/home/brad/NetBeansProjects/BGEvolver/lib/benchmarks/nop.red")

nop.breed(20, 10, 10, 10,
“/home/brad/NetBeansProjects/BGEvolver/lib/dumpingfolder”, 0)

Do you have a Ruby Corewars implementation? I’ve been working on a
Corewars-related project off and on, and it’d be nice if there were
another
implementation I could go off of that wasn’t Digital MARS.

Here’s my project:

https://github.com/tarcieri/badgewars

Tony A. wrote in post #980956:

Do you have a Ruby Corewars implementation? I’ve been working on a
Corewars-related project off and on, and it’d be nice if there were
another
implementation I could go off of that wasn’t Digital MARS.

Here’s my project:

https://github.com/tarcieri/badgewars

No I don’t have a Ruby Corewars implementation, however if you do end up
completing yours I’d very much like to use it in my evolver to eliminate
the need for it to interact with an external mars.

How are you doing that? I’d be curious. I need to check my
implementation
against pMARS, and right now I’m doing it manually :confused:

I’ll have to check that out. Do you have any examples of your pMARS
interfacing you can share?

well I’m not done coding that yet but in ruby it’s relatively easy as
you can pass system commands and recieve the returns quite easily.

Ok, so it looks like this is the only really relevant code:

def breed(offspring, chancecommand, chancenumber1, chancenumber2,
destfolder, botidcounter)
counter = 0
while counter < offspring
tmp = self.dup
tmp.mutate(chancecommand,
chancenumber1,chancenumber2).save(destfolder+"/"+((botidcounter +=
1).to_s)+".RED")
counter += 1
end
return botidcounter
end

nop.breed(20, 10, 10, 10,
“/home/brad/NetBeansProjects/BGEvolver/lib/dumpingfolder”, 0)

If I’m understanding this right, it will take the current warrior and
breed
20 new, mutated versions of it. How is this different from what you
want?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs