Maker Pro
Maker Pro

Skybuck's Wolfram (Turing-Like) Machine implementation

S

Skybuck Flying

Heeeeellllooooooo,

Slashdot.org yes which I read brought something to my attention:

http://www.wolframscience.com/prizes/tm23/turingmachine.html


A minimalistic CPU !

I like minimalistic shit.

And especially ROBUST SHIT.

And it seems MEGA FUCKING ROBUST CONCEPT ;)

So NATURALLY I HAD TO IMPLEMENT IT TO SEE IT IN ACTION.

Here is my quick and simple implementation to experiment and play with
Wolfram/Turing Like/Minimalistic machine ;)

Nicely seperated into a re-usable module.

I'll also include a simple GUI.

Just add a string grid, and a panel with 2 buttons on it or so. And setup
the OnClicks properly.

The rest is down by the buttons... one initialize button and one step
button.

The gui example is also very simple man ! I haven't programmed a GUI in
ages... actually that's not true... but it feels like it.

Me been in "engine land" so lonnnnggg hahahahahaha, so I know a thing or two
about writing "engines" ;)

And so here is the fricking engine baby ! with some comments and
"documentation" too for the clueless ;)

What did kinda surprise me is that "they" call it a Wolfram 2-3 machine.

But in reality it's really a 2-3-2 machine. Because each transition also
needs a move specifier.

They say so on the website and it's also required and logical otherwise it
won't function properly.

So I am not sure what that's all about... Is 2-3 same as 2-3-2 ? Hmmm
Depends on your points of view me thinks ;)

Ofcourse one could describe the last 2 simply as the action the machine must
take... go left or go right... that's all it can do ;)

So I guess it's valid ;)

// *** Begin of Module Code ***

unit Unit_TwolframMachine_version_002;

{

Skybuck's implementation of Wolfram's (Turing-like) Machine

Version 0.02 created on 25 october 2007 by Skybuck Flying ;)

Debugged and working correctly it seems.

No usage example yet except for a simple debug/demonstration program.

I think I am gonna try and use this stuff for some AI in a game
and I can think of two ways I am gonna use this stuff:

Way 1:

"Creating random robust computer programs"

Way 2:

"Modifieing robust computer programs"

The robustness and the completeness of this machine (at least so they claim)
seems
very interesting.

I am not yet sure how I am gonna use it... that's what I am gonna find out
some day.

However I have other project which needs attention too..

But I just couldn't let this one slip by unnoticed or unprogrammed :)

Because it's way too cool !

And because I wanna see some nice and interesting Delphi
programs/applications
which use this stuff I am gonna share it with you the people of the
internet/usenet.

I know you a bunch of assholes and idiots.. LOL... but one never knows...

Somebody, somewhere on this planet might actually do something cooooooOOOOOL
with it ;)

Yes and if not then IIIIII might do something cool with it !

For now it's going into the freezer because I have no time to play with it.

Or maybe I will play with it... I don't know yet.

BUT SHARE SHARE SHARE THIS BRAVE NEW WORLD LOL ;) LOL

I like this minimilazotion shit !

Especially because it seems ROBUST MAN !!

What a tiny CPU ! LOVING IT ! ;)

Some documentation for the clueless how to use it:

Simply call initialize once.

Then simply call execute repeatedly to run a program/processor which uses
the embedded tape player/recorder.

Use the input/output fields of machine to understand what it did after each
run ;)

If you need a bigger tape then simply change TwolframPosition to something
bigger ;)

Good luck !

See example code for short little gui example ;) it could be a console
example as well but I choose gui.
Actually I have both examples... but gui example almost the same ;)

}

interface

type
// TwolframPosition = 1..10*1000*1000; // 1 to 10 million positions on tape
available for now ;)
TwolframPosition = 1..100; // for now let's just use 100 for easy
displaying.

TwolframState = ( ws_prev, ws_next ); // up/down in picture ;)
TwolframColor = ( wc_orange, wc_yellow, wc_white );
TwolframMove = ( wm_left, wm_right );

TwolframOutput = record
OutputState : TwolframState;
OutputColor : TwolframColor;
OutputMove : TwolframMove;
end;

TwolframTransition = array[TwolframState] of array[TwolframColor] of
TwolframOutput;

TwolframTape = array[TWolframPosition] of TwolframColor;

TwolframMachine = record
mInputState : TwolframState; // remembers last input state
mInputColor : TwolframColor; // remembers last input color
mInputPosition : TwolframPosition; // remembers last input position

mOutputState : TwolframState; // remembers last output state
mOutputColor : TwolframColor; // remembers last output color
mOutputPosition : TwolframPosition; // remembers last output position
mOutputMove : TwolframMove;

mState : TwolframState; // current state
mHead : TwolframPosition; // current head position

mTape : TwolframTape;
mProcessor : TwolframTransition;

procedure SetupProcessor;
procedure Initialize;
procedure Execute;
end;

implementation

procedure TwolframMachine.SetupProcessor;
begin
// state up
mProcessor[ws_prev][wc_orange].OutputState := ws_prev;
mProcessor[ws_prev][wc_orange].OutputColor := wc_yellow;
mProcessor[ws_prev][wc_orange].OutputMove := wm_left;

mProcessor[ws_prev][wc_yellow].OutputState := ws_prev;
mProcessor[ws_prev][wc_yellow].OutputColor := wc_orange;
mProcessor[ws_prev][wc_yellow].OutputMove := wm_left;

mProcessor[ws_prev][wc_white].OutputState := ws_next;
mProcessor[ws_prev][wc_white].OutputColor := wc_yellow;
mProcessor[ws_prev][wc_white].OutputMove := wm_right;

// state down
mProcessor[ws_next][wc_orange].OutputState := ws_prev;
mProcessor[ws_next][wc_orange].OutputColor := wc_white;
mProcessor[ws_next][wc_orange].OutputMove := wm_right;

mProcessor[ws_next][wc_yellow].OutputState := ws_next;
mProcessor[ws_next][wc_yellow].OutputColor := wc_orange;
mProcessor[ws_next][wc_yellow].OutputMove := wm_right;

mProcessor[ws_next][wc_white].OutputState := ws_prev;
mProcessor[ws_next][wc_white].OutputColor := wc_orange;
mProcessor[ws_next][wc_white].OutputMove := wm_left;
end;

procedure TwolframMachine.Initialize;
var
vPosition : TwolframPosition;
begin
SetupProcessor;

// position head at center of tape.
mHead := High(TwolframPosition) div 2;

// start state is prev
mState := ws_prev;

// clear tape
for vPosition := Low(TwolframPosition) to High(TwolframPosition) do
begin
mTape[vPosition] := wc_white;
end;
end;

procedure TwolframMachine.Execute;
begin
mInputPosition := mHead;
mInputColor := mTape[mHead];
mInputState := mState;

mOutputState := mProcessor[mState][mInputColor].OutputState;
mOutputColor := mProcessor[mState][mInputColor].OutputColor;
mOutputPosition := mHead;
mOutputMove := mProcessor[mState][mInputColor].OutputMove;

// update tape contents
mTape[mHead] := mOutputColor;

// update head position
case mOutputMove of
wm_left :
begin
mHead := Pred(mHead);
end;

wm_right :
begin
mHead := Succ(mHead);
end;
end;

// update state
mState := mOutputState;
end;

end.

// *** End of Module Code ***

// *** Begin of GUI Example ***

unit UnitGuiMain;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids;

type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
StringGridTape: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses
Unit_TwolframMachine_version_002;

var
WolframMachine : TwolframMachine;
Step : integer;

procedure TForm1.Button1Click(Sender: TObject);
begin
Step := 1;
WolframMachine.Initialize;

StringGridTape.ColCount := High(TwolframPosition) + 2;
StringGridTape.RowCount := 1000;
StringGridTape.DefaultColWidth := 16;
StringGridTape.DefaultRowHeight := 16;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
WolframMachine.Execute;

case WolframMachine.mOutputColor of
wc_orange :
begin
StringGridTape.Cells[WolframMachine.mOutputPosition, Step] := 'o';
end;

wc_yellow :
begin
StringGridTape.Cells[WolframMachine.mOutputPosition, Step] := 'y';
end;

wc_white :
begin
StringGridTape.Cells[WolframMachine.mOutputPosition, Step] := 'w';
end;
end;

Step := Step + 1;
end;

end.

// *** End of GUI Example ***

And as a bunch of motherfuckers says:

ENJOY !

But this time this stuff is really enjoyable ! hahahahaha LOL.

I am probably gonna use it for a game ai... and try and make the game
program the ai itself.

But maybe I first try a simple maze solver or so ;)

Please let me know if you did something reallllly interesting with it IN
DELPHI ! ;)

skybuck 2000 at hotmail dot com

if you managed to do something interesting with it ;)

I shall include asm too because those guys kinda used to programming
minimalistic shit lol.

EAT THAT ! ;)

And electronics too in case they wanna implement it in hardware LOL
hahahaha.

Yeah, me just showing off my programming skills too HAHAHAHAHAHAHAHA.

Bye,
Skybuck.
 
S

Skybuck Flying

After reading somebodie's else bullshit in another unrelated thread I was
under the impression that pred and succ automatically wrap around, that's
not the case.

I wanted the head to wrap around the ends of the tape.

This emulates a tape where the ends are stuck together in a circular
fashion.

I am not sure if "wrap around" is allowed in turing machines... but this
could emulate "infinite memory" a little bit better than just "crashing" or
"hanging" because of out of memory situations.

At least now it will never run out of memory because it can just overwrite
other older memory.

Here is the little fix/update/patch for the head movement to make wrap
around possible :)


// update head position
// wrap arounds possible.
case mOutputMove of
wm_left :
begin
if mHead = Low(TwolframPosition) then
begin
mHead := High(TwolframPosition);
end else
begin
mHead := Pred(mHead);
end;
end;

wm_right :
begin
if mHead = High(TwolframPosition) then
begin
mHead := Low(TwolframPosition);
end else
begin
mHead := Succ(mHead);
end;
end;
end;

(Note: untested but should work ;) :))

Bye,
Skybuck.
 
D

default

On Thu, 25 Oct 2007 12:36:13 +0200, "Skybuck Flying"

Does this mean you've perfected your resonant energy beam generator
and are moving on to other things?
 
W

Wolfgang Kern

default" said:
Does this mean you've perfected your resonant energy beam generator
and are moving on to other things? ....
and West-Coast Server Farms - Total Privacy via Encryption =----

And weird questions like this were the prime reason for me and others
to keep the "Flying Bucket" in the 'quiet cage' since years.

BUT:
If you got any question about ASM-solutions I (or erveryone else in A.L.A)
might answer it, because plain-ASM-x86 or sometimes even other CPU's related
questions are the main reason why our A.L.A exists at all.
Skybuck questions can be ignored, even I may see some creative potential,
the obvious ignorance of this guy will never fit reality needs ...
__
wolfgang

ther's no need to be aware, A.L.A members are usually kind :)
as long you avoid to mention the never ASM-fitting shit: called HLA.
 
O

Orlando B. Salazar

Wolfgang said:
ther's no need to be aware, A.L.A members are usually kind :)
as long you avoid to mention the never ASM-fitting shit: called HLA.

Judging by your persistent cavalier and condescending attitude,
your refusal to carry on in a civil manner, and also by your inability
to spell simple English words correctly, I'm sure you meant to say
the users of Rene's highly inferior Rosasm would rather not have
anyone mention the much more superior product of Randall Hyde,
HLA, because they know they haven't a chance at succeeding while
in competition with it.

You just couldn't refuse ending your post without taking a stab at HLA.
So, now you must reap what you have sown; now you pay the consequences
for your mistake.


Regards,
Orlando B. Salazar
 
S

Skybuck Flying

Hello,

I can't let it go... I have to investigate this Wolfram stuff otherwise it
keep thinking about it LOL.

Anyway.

To figure out how this stuff works first I investigate which colors occur
more often.

Those might be used to encode high level values to create higher level
states and transitions or so:

The investigation module below examines how often a color occurs in
sequence.

My reasoning is: These sequences of the same colors might be used to encode
higher level values for example:

2 Oranges in a row = Do Action 1
3 Oranges in a row = Do Action 2
4 Oranges in a row = Do Action 3

2 Yellows in a row = Do Action 4
3 Yellows in a row = Do Action 5
4 Yellows in a row = Do Action 6

This reasoning seems a good way to do it..

Because the investigation module below already shows that white almost near
occurs twice ?

Apperently white simply means "empty memory".

I am not sure which value occurs more often orange or yellow..

Or maybe orange can be seen as a digital one. and yellow as a digital zero
or so..

and white simply as non content/meaning:

Simple Investigation module:

// *** Begin of Investigation Module ***

unit unit_TcombatAI_version_001;

interface

uses
Unit_TwolframMachine_version_002;

type
TcombatAI = record
private
public
mWolframMachine : TwolframMachine;
mOrangeOutputs : integer;
mYellowOutputs : integer;
mWhiteOutputs : integer;

procedure Initialize;
procedure Execute;
end;

implementation

uses
Dialogs;

procedure TcombatAi.Initialize;
var
vWolframPosition : TwolframPosition;
begin
mWolframMachine.Initialize;

// fill program with random colors
for vWolframPosition := Low(TwolframPosition) to High(TwolframPosition) do
begin
mWolframMachine.mTape[vWolframPosition] := TwolframColor(Random(
Ord(High(TwolframColor))+1 ) );
end;
end;

procedure TcombatAi.Execute;
begin

mWolframMachine.Execute;

// determine number of consecutive/sequential outputs of same color.
case mWolframMachine.mOutputColor of
wc_orange :
begin
mOrangeOutputs := mOrangeOutputs + 1;
mYellowOutputs := 0;
mWhiteOutputs := 0;

case mOrangeOutputs of
2 :
begin
ShowMessage('Two Oranges !');
end;
end;
end;

wc_yellow :
begin
mOrangeOutputs := 0;
mYellowOutputs := mYellowOutputs + 1;
mWhiteOutputs := 0;

case mYellowOutputs of
2 :
begin
ShowMessage('Two Yellows !');
end;
end;

end;

wc_white :
begin
mOrangeOutputs := 0;
mYellowOutputs := 0;
mWhiteOutputs := mWhiteOutputs + 1;

case mWhiteOutputs of
2 :
begin
ShowMessage('Two Whites !');
end;
end;

end;
end;
end;


end.

// *** End of Investigation Module ***

Bye,
Skybuck.
 
S

Skybuck Flying

This is a better investigation module.

It simply shows how many times the same color occurs in a row.

Also randomize on timer added ;)

// *** Begin of Module ***

unit unit_TcombatAI_version_001;

interface

uses
Unit_TwolframMachine_version_002;

type
TcombatAI = record
private
public
mWolframMachine : TwolframMachine;
mOrangeOutputs : integer;
mYellowOutputs : integer;
mWhiteOutputs : integer;

procedure Initialize;
procedure Execute;
end;

implementation

uses
SysUtils, Dialogs;

procedure TcombatAi.Initialize;
var
vWolframPosition : TwolframPosition;
begin
mWolframMachine.Initialize;

// fill program with random colors
for vWolframPosition := Low(TwolframPosition) to High(TwolframPosition) do
begin
mWolframMachine.mTape[vWolframPosition] := TwolframColor(Random(
Ord(High(TwolframColor))+1 ) );
end;
end;

procedure TcombatAi.Execute;
begin

mWolframMachine.Execute;

// determine number of consecutive/sequential outputs of same color.
case mWolframMachine.mOutputColor of
wc_orange :
begin
mOrangeOutputs := mOrangeOutputs + 1;
mYellowOutputs := 0;
mWhiteOutputs := 0;

if mOrangeOutputs >= 2 then
begin
ShowMessage('Oranges: ' + IntToStr(mOrangeOutputs) );
end;
end;

wc_yellow :
begin
mOrangeOutputs := 0;
mYellowOutputs := mYellowOutputs + 1;
mWhiteOutputs := 0;

if mYellowOutputs >= 2 then
begin
ShowMessage('Yellows: ' + IntToStr(mYellowOutputs) );
end;
end;

wc_white :
begin
mOrangeOutputs := 0;
mYellowOutputs := 0;
mWhiteOutputs := mWhiteOutputs + 1;

if mWhiteOutputs >= 2 then
begin
ShowMessage('Whites: ' + IntToStr(mWhiteOutputs) );
end;
end;
end;
end;


end.

// *** End of Module ***

Bye,
Skybuck.
 
S

Skybuck Flying

While,

The combat's game AI has 5 actions available:

forward
brake
turn left
turn right
fire

I wolfram-encoded them as:

forward // 2 oranges
brake // 2 yellows
turn left // 3 oranges
turn right // 3 yellows
fire // 4 oranges or 4 yellows

Here is the code and now I go test it in my game to see what happens lol.

I expect the planes to simply rotate and fire sometimes.

The next idea is to implement "hurt" when they get fired upon and hit some
memory contents/tape will be changed to hopefully improve the ai's program.
(Already done: ai's program initialized with random program/tape/colors ;)
maybe later stored and loaded from disk if ai actually learns)

// *** Begin of Module ***

unit unit_TcombatAI_version_001;

interface

uses
Unit_TwolframMachine_version_002;

type
TcombatAI = record
private
public
mWolframMachine : TwolframMachine;
mOrangeOutputs : integer;
mYellowOutputs : integer;
mWhiteOutputs : integer;

mForward : boolean;
mBrake : boolean;
mTurnLeft : boolean;
mTurnRight : boolean;
mFire : boolean;

procedure Initialize;
procedure Execute;

procedure ExecuteOrangeAction;
procedure ExecuteYellowAction;
// procedure ExecuteWhiteAction;
end;

implementation

uses
SysUtils, Dialogs;

procedure TcombatAi.Initialize;
var
vWolframPosition : TwolframPosition;
begin
Randomize;

mWolframMachine.Initialize;

// fill program with random colors
for vWolframPosition := Low(TwolframPosition) to High(TwolframPosition) do
begin
mWolframMachine.mTape[vWolframPosition] := TwolframColor(Random(
Ord(High(TwolframColor))+1 ) );
end;
end;

procedure TcombatAI.ExecuteOrangeAction;
begin
if mOrangeOutputs = 2 then
begin
mForward := true;
end else
if mOrangeOutputs = 3 then
begin
mTurnLeft := true;
end else
if mOrangeOutputs = 4 then
begin
mFire := true;
end;
end;

procedure TcombatAI.ExecuteYellowAction;
begin
if mYellowOutputs = 2 then
begin
mBrake := true;
end else
if mYellowOutputs = 3 then
begin
mTurnRight := true;
end else
if mYellowOutputs = 4 then
begin
mFire := true;
end;
end;

procedure TcombatAI.Execute;
begin

{
Combat AI has 5 actions available:

mForward (boolean) // will be encoded as orange 2

mBrake (boolean) // will be encoded as yellow 2

mTurnLeft (boolean) // will be encoded as orange 3

mTurnRight (boolean) // will be encoded as yellow 3

mFire (boolean) // will be encoded as yellow 4 or orange 4
}

// reset ai actions

mForward := false;
mBrake := false;
mTurnLeft := false;
mTurnRight := false;
mFire := false;

mWolframMachine.Execute;


// determine number of consecutive/sequential outputs of same color.
case mWolframMachine.mOutputColor of
wc_orange :
begin
mOrangeOutputs := mOrangeOutputs + 1;

// if color change detected then execute previous color
if mYellowOutputs >= 2 then
begin
ExecuteYellowAction;
end;

// if max color reach then execute color
if mOrangeOutputs = 4 then
begin
ExecuteOrangeAction;
mOrangeOutputs := 0;
end;

mYellowOutputs := 0;
mWhiteOutputs := 0;
end;

wc_yellow :
begin
mYellowOutputs := mYellowOutputs + 1;

// if color change detected then execute previous color
if mOrangeOutputs >= 2 then
begin
ExecuteOrangeAction;
end;

// if max color reach then execute color
if mYellowOutputs = 4 then
begin
ExecuteYellowAction;
mYellowOutputs := 0;
end;

mOrangeOutputs := 0;
mWhiteOutputs := 0;
end;

wc_white :
begin
mWhiteOutputs := mWhiteOutputs + 1;

{
// 2 whites doesn't seem to happen ;)
if mWhiteOutputs >= 2 then
begin
ShowMessage('Whites: ' + IntToStr(mWhiteOutputs) );
end;
}

mOrangeOutputs := 0;
mYellowOutputs := 0;
end;
end;
end;

end.

// *** End of Module ***

Bye,
Skybuck.
 
S

Skybuck Flying

Hello Bitches !

I fucked around a little bit with my game and wolfram ai and I also
implemented load and save functionality so that tapes can be load and saved.

And I also put everything you need to play the game on my website where you
can download it.

You need

Combat.exe

and:

LEVEL2C.3DS

Download at:

http://members.home.nl/hbthouppermans/Combat/

Then simply play the game and you be ok buddy !.

After game exists, tapes are saved !

Each tape needs 2 MB.

Then later when game is started/loaded again the tapes are loaded !

Now you can make your own game ai if you have a tape editor.

No tape editor exists yet.

Furthermore here is the source code for the updated wolfram implementation
and also the combat ai...

It has a think method and it has a hit and self hit method which tell it
what to do when it's hit... it's described further in the comments.

It's all very basic but kinda funny too and same behaviour can be seen in
the game.

I have big computer so I simply run with 250 ai's ;)

Then can be set in the game menu too..

Have fun.

// *** Begin of Wolfram Module ***

unit Unit_TwolframMachine_version_002;

{

Skybuck's implementation of Wolfram's (Turing-like) Machine

Version 0.02 created on 25 october 2007 by Skybuck Flying ;)

Debugged and working correctly it seems.

No usage example yet except for a simple debug/demonstration program.

I think I am gonna try and use this stuff for some AI in a game
and I can think of two ways I am gonna use this stuff:

Way 1:

"Creating random robust computer programs"

Way 2:

"Modifieing robust computer programs"

The robustness and the completeness of this machine (at least so they claim)
seems
very interesting.

I am not yet sure how I am gonna use it... that's what I am gonna find out
some day.

However I have other project which needs attention too..

But I just couldn't let this one slip by unnoticed or unprogrammed :)

Because it's way too cool !

And because I wanna see some nice and interesting Delphi
programs/applications
which use this stuff I am gonna share it with you the people of the
internet/usenet.

I know you a bunch of assholes and idiots.. LOL... but one never knows...

Somebody, somewhere on this planet might actually do something cooooooOOOOOL
with it ;)

Yes and if not then IIIIII might do something cool with it !

For now it's going into the freezer because I have no time to play with it.

Or maybe I will play with it... I don't know yet.

BUT SHARE SHARE SHARE THIS BRAVE NEW WORLD LOL ;) LOL

I like this minimilazotion shit !

Especially because it seems ROBUST MAN !!

What a tiny CPU ! LOVING IT ! ;)

Some documentation for the clueless how to use it:

Simply call initialize once.

Then simply call execute repeatedly to run a program/processor which uses
the embedded tape player/recorder.

Use the input/output fields of machine to understand what it did after each
run ;)

If you need a bigger tape then simply change TwolframPosition to something
bigger ;)

Good luck !

See example code for short little gui example ;) it could be a console
example as well but I choose gui.
Actually I have both examples... but gui example almost the same ;)

Based on story at:

http://www.wolframscience.com/prizes/tm23/turingmachine.html

}

{

version 0.02 Updated on 28 october 2007 by Skybuck Flying

method: SaveTape added
method: LoadTape added

}

interface

type
TwolframPosition = 1..2*1000*1000; // 1 to 10 million positions on tape
available for now ;)
// TwolframPosition = 1..100; // for now let's just use 100 for easy
displaying.

TwolframState = ( ws_prev, ws_next ); // up/down in picture ;)
TwolframColor = ( wc_orange, wc_yellow, wc_white );
TwolframMove = ( wm_left, wm_right );

TwolframOutput = record
OutputState : TwolframState;
OutputColor : TwolframColor;
OutputMove : TwolframMove;
end;

TwolframTransition = array[TwolframState] of array[TwolframColor] of
TwolframOutput;

TwolframTape = packed array[TWolframPosition] of TwolframColor;

TwolframMachine = record
mInputState : TwolframState; // remembers last input state
mInputColor : TwolframColor; // remembers last input color
mInputPosition : TwolframPosition; // remembers last input position

mOutputState : TwolframState; // remembers last output state
mOutputColor : TwolframColor; // remembers last output color
mOutputPosition : TwolframPosition; // remembers last output position
mOutputMove : TwolframMove;

mState : TwolframState; // current state
mHead : TwolframPosition; // current head position

mTape : TwolframTape;
mProcessor : TwolframTransition;

procedure SetupProcessor;
procedure Initialize;
procedure Execute;

procedure SaveTape( ParaFileName : string );
procedure LoadTape( ParaFileName : string );
end;

implementation

uses
Classes, SysUtils;

procedure TwolframMachine.SetupProcessor;
begin
// state up
mProcessor[ws_prev][wc_orange].OutputState := ws_prev;
mProcessor[ws_prev][wc_orange].OutputColor := wc_yellow;
mProcessor[ws_prev][wc_orange].OutputMove := wm_left;

mProcessor[ws_prev][wc_yellow].OutputState := ws_prev;
mProcessor[ws_prev][wc_yellow].OutputColor := wc_orange;
mProcessor[ws_prev][wc_yellow].OutputMove := wm_left;

mProcessor[ws_prev][wc_white].OutputState := ws_next;
mProcessor[ws_prev][wc_white].OutputColor := wc_yellow;
mProcessor[ws_prev][wc_white].OutputMove := wm_right;

// state down
mProcessor[ws_next][wc_orange].OutputState := ws_prev;
mProcessor[ws_next][wc_orange].OutputColor := wc_white;
mProcessor[ws_next][wc_orange].OutputMove := wm_right;

mProcessor[ws_next][wc_yellow].OutputState := ws_next;
mProcessor[ws_next][wc_yellow].OutputColor := wc_orange;
mProcessor[ws_next][wc_yellow].OutputMove := wm_right;

mProcessor[ws_next][wc_white].OutputState := ws_prev;
mProcessor[ws_next][wc_white].OutputColor := wc_orange;
mProcessor[ws_next][wc_white].OutputMove := wm_left;
end;

procedure TwolframMachine.Initialize;
var
vPosition : TwolframPosition;
begin
SetupProcessor;

// position head at center of tape.
mHead := High(TwolframPosition) div 2;

// start state is prev
mState := ws_prev;

// clear tape
for vPosition := Low(TwolframPosition) to High(TwolframPosition) do
begin
mTape[vPosition] := wc_white;
end;
end;

procedure TwolframMachine.Execute;
begin
mInputPosition := mHead;
mInputColor := mTape[mHead];
mInputState := mState;

mOutputState := mProcessor[mState][mInputColor].OutputState;
mOutputColor := mProcessor[mState][mInputColor].OutputColor;
mOutputPosition := mHead;
mOutputMove := mProcessor[mState][mInputColor].OutputMove;

// update tape contents
mTape[mHead] := mOutputColor;

// update head position
// wrap arounds possible.
case mOutputMove of
wm_left :
begin
if mHead = Low(TwolframPosition) then
begin
mHead := High(TwolframPosition);
end else
begin
mHead := Pred(mHead);
end;
end;

wm_right :
begin
if mHead = High(TwolframPosition) then
begin
mHead := Low(TwolframPosition);
end else
begin
mHead := Succ(mHead);
end;
end;
end;

// update state
mState := mOutputState;
end;

procedure TwolframMachine.SaveTape( ParaFileName : string );
var
vFileStream : TfileStream;
vTapePosition : TwolframPosition;
vBytesToWrite : integer;
vBytesWritten : integer;
begin
vFileStream := TfileStream.Create( ParaFileName, fmCreate or
fmShareDenyNone );

vTapePosition := Low(TwolframPosition);
while vTapePosition < High(TwolframPosition) do
begin
vBytesToWrite := High(TwolframPosition) - vTapePosition;
if vBytesToWrite > 4*1024 then vBytesToWrite := 4*1024;
vBytesWritten := vFileStream.Write( mTape[vTapePosition], vBytesToWrite );
vTapePosition := vTapePosition + vBytesWritten;
end;

vFileStream.Free;
end;

procedure TwolframMachine.LoadTape( ParaFileName : string );
var
vFileStream : TfileStream;
vTapePosition : TwolframPosition;
vBytesToRead : integer;
vBytesRead : integer;
begin
vFileStream := TfileStream.Create( ParaFileName, fmOpenRead or
fmShareDenyNone );

vTapePosition := Low(TwolframPosition);
while vTapePosition < High(TwolframPosition) do
begin
vBytesToRead := High(TwolframPosition) - vTapePosition;
if vBytesToRead > 4*1024 then vBytesToRead := 4*1024;
vBytesRead := vFileStream.Read( mTape[vTapePosition], vBytesToRead );
vTapePosition := vTapePosition + vBytesRead;
end;

vFileStream.Free;
end;


end.

// *** End of Wolfram Module ***

// *** Begin of Combat AI ***

unit unit_TcombatAI_version_002;


{

Combat AI version 0.02 created on 28 october 2007 by Skybuck Flying.

Kinda funny stuff.

Memory content/color increment if ship hit.
Memory content partially cleared/randomized at head position on ship self
damage.

Load/Save tape used to load/save ai to disk.

If no tape file present then random program ai will be generated.

All AI saved to disk.

Each tape needs 2 MB of space.

Think method add which thinks until a decision is made or loop ends.

Hit procedure called when ai gets hit by other ship
SelfHit procedure called when ai gets hit by himself.

}

interface

uses
Unit_TwolframMachine_version_002;

type
TwolframPositionMemory = 1..20;

TcombatAI = record
private
public
mWolframMachine : TwolframMachine;
mOrangeOutputs : integer;
mYellowOutputs : integer;
mWhiteOutputs : integer;

mForward : boolean;
mBrake : boolean;
mTurnLeft : boolean;
mTurnRight : boolean;
mFire : boolean;

mHeadPositionMemory : array[TwolframPositionMemory] of TwolframPosition;

procedure Initialize;
procedure Execute;

procedure Think( ParaCount : integer );

procedure Hit;
procedure SelfHit;

procedure ExecuteOrangeAction;
procedure ExecuteYellowAction;
// procedure ExecuteWhiteAction;
end;

implementation

uses
SysUtils, Dialogs;

procedure TcombatAi.Initialize;
var
vWolframPosition : TwolframPosition;
vLoops : integer;
vRandoms : integer;
vColor : TwolframColor;
begin

Randomize;

mWolframMachine.Initialize;

// fill program with random colors

vWolframPosition := Low(TwolframPosition);

repeat

vRandoms := 1+ Random(100);
vColor := TwolframColor(Random( Ord(High(TwolframColor))+1 ) );
vLoops := 0;
repeat
mWolframMachine.mTape[vWolframPosition] := vColor;
vWolframPosition := Succ(vWolframPosition);
vLoops := vLoops + 1;
until (vWolframPosition = High(TwolframPosition)) or (vLoops = vRandoms);

until vWolframPosition = High(TwolframPosition);

{
for vWolframPosition := Low(TwolframPosition) to High(TwolframPosition) do
begin
mWolframMachine.mTape[vWolframPosition] := TwolframColor(Random(
Ord(High(TwolframColor))+1 ) );
end;
}
end;

procedure TcombatAI.ExecuteOrangeAction;
begin
if mOrangeOutputs = 2 then
begin
mForward := true;
end else
if mOrangeOutputs = 3 then
begin
mTurnLeft := true;
end else
if mOrangeOutputs = 4 then
begin
mFire := true;
end;
end;

procedure TcombatAI.ExecuteYellowAction;
begin
if mYellowOutputs = 2 then
begin
mBrake := true;
end else
if mYellowOutputs = 3 then
begin
mTurnRight := true;
end else
if mYellowOutputs = 5 then
begin
mFire := true;
end;
end;

procedure TcombatAI.Execute;
var
vHeadPositionMemoryIndex : TwolframPositionMemory;
begin

{
Combat AI has 5 actions available:

mForward (boolean) // will be encoded as orange 2

mBrake (boolean) // will be encoded as yellow 2

mTurnLeft (boolean) // will be encoded as orange 3

mTurnRight (boolean) // will be encoded as yellow 3

mFire (boolean) // will be encoded as yellow 4 or orange 4
}

// reset ai actions

mForward := false;
mBrake := false;
mTurnLeft := false;
mTurnRight := false;
mFire := false;

// remember positions // top index last position
// shift downwards
for vHeadPositionMemoryIndex := High(TwolframPositionMemory) downto
Succ(Low(TwolframPositionMemory)) do
begin
mHeadPositionMemory[Pred(vHeadPositionMemoryIndex)] :=
mHeadPositionMemory[vHeadPositionMemoryIndex];
end;

// store new
mHeadPositionMemory[High(TwolframPositionMemory)] := mWolframMachine.mHead;

mWolframMachine.Execute;

// determine number of consecutive/sequential outputs of same color.
case mWolframMachine.mOutputColor of
wc_orange :
begin
mOrangeOutputs := mOrangeOutputs + 1;

// if color change detected then execute previous color
if mYellowOutputs >= 2 then
begin
ExecuteYellowAction;
end;

// if max color reach then execute color
if mOrangeOutputs = 4 then
begin
ExecuteOrangeAction;
mOrangeOutputs := 0;
end;

mYellowOutputs := 0;
mWhiteOutputs := 0;
end;

wc_yellow :
begin
mYellowOutputs := mYellowOutputs + 1;

// if color change detected then execute previous color
if mOrangeOutputs >= 2 then
begin
ExecuteOrangeAction;
end;

// if max color reach then execute color
if mYellowOutputs = 4 then
begin
ExecuteYellowAction;
mYellowOutputs := 0;
end;

mOrangeOutputs := 0;
mWhiteOutputs := 0;
end;

wc_white :
begin
mWhiteOutputs := mWhiteOutputs + 1;

{
// 2 whites doesn't seem to happen ;)
if mWhiteOutputs >= 2 then
begin
ShowMessage('Whites: ' + IntToStr(mWhiteOutputs) );
end;
}

mOrangeOutputs := 0;
mYellowOutputs := 0;
end;
end;
end;

procedure TcombatAI.Think( ParaCount : integer );
var
vLoopCount : integer;
begin
vLoopCount := 0;
repeat
Execute;
vLoopCount := vLoopCount + 1;

// loop until a decision has been made or think loopout
until (mForward or mBrake or mTurnLeft or mTurnRight or mFire) or
(vLoopCount = ParaCount);
end;

procedure TcombatAI.Hit;
var
vHeadPositionMemoryIndex : TwolframPositionMemory;
begin
// clear last memory positions
// increment last memory in modes.

if mWolframMachine.mTape[ mWolframMachine.mOutputPosition ] =
High(TwolframColor) then
begin
mWolframMachine.mTape[ mWolframMachine.mOutputPosition ] :=
Low(TwolframColor);
end else
begin
mWolframMachine.mTape[ mWolframMachine.mOutputPosition ] :=
Succ(mWolframMachine.mOutputColor);
end;
{
for vHeadPositionMemoryIndex := High(TwolframPositionMemory) downto
Low(TwolframPositionMemory) do
begin
// get us out of here move it... so go forward or turn
mWolframMachine.mTape[ mHeadPositionMemory[vHeadPositionMemoryIndex] ] :=
TwolframColor( Random(Ord(High(TwolframColor))+1) );
// mWolframMachine.mTape[ mHeadPositionMemory[vHeadPositionMemoryIndex] ]
:= wc_white;
end;
}

end;

// ai is hitting itself clear it's memory of last positions
// and also around current position
procedure TcombatAI.SelfHit;
var
vHeadPositionMemoryIndex : TwolframPositionMemory;
vHead : TwolfRamPosition;
vLoops : integer;
begin
// clear last memory positions
for vHeadPositionMemoryIndex := High(TwolframPositionMemory) downto
Low(TwolframPositionMemory) do
begin
// get us out of here move it... so go forward or turn
// mWolframMachine.mTape[ mHeadPositionMemory[vHeadPositionMemoryIndex] ]
:= TwolframColor( Random(Ord(High(TwolframColor))+1) );
mWolframMachine.mTape[ mHeadPositionMemory[vHeadPositionMemoryIndex] ] :=
wc_white;
end;

mWolframMachine.mTape[ mWolframMachine.mHead ] := wc_white;

vHead := mWolframMachine.mHead;
for vLoops := 1 to 10 do
begin
if (Pred(vHead) > Low(TwolframPosition)) then
begin
mWolframMachine.mTape[ vHead ] := wc_white;
vHead := Pred(vHead);
end;

// also add a bit of randomness
if (Pred(vHead) > Low(TwolframPosition)) then
begin
mWolframMachine.mTape[ vHead ] := TwolframColor(
Random(Ord(High(TwolframColor))+1) );
vHead := Pred(vHead);
end;
end;

vHead := mWolframMachine.mHead;
for vLoops := 1 to 10 do
begin
if (Succ(vHead) < High(TwolframPosition)) then
begin
mWolframMachine.mTape[ vHead ] := wc_white;
vHead := Succ(vHead);
end;

// also add a bit of randomness
if (Succ(vHead) < High(TwolframPosition)) then
begin
mWolframMachine.mTape[ vHead ] := TwolframColor(
Random(Ord(High(TwolframColor))+1) );
vHead := Succ(vHead);
end;

end;

end;


end.

// *** End of Combat AI ***

Bye,
Skybuck.
 
S

Skybuck Flying

No wonder it's not working.

Some say wolfram's 2-3 machine aint universal LOL.

Good excuse ! LOL.

Newsserver problems remain for me and my isp.

(Not so universal says so on slashdot :p*)

Bye,
Skybuck.
 
S

Skybuck Flying

I made new news account.

I think this solves the problem for now.

Kinda sux how switching news server fucks up an outlook express account ?!?

(Have to re add newsgroups now ?!? :( )

Bye,
Skybuck.
 
R

Rudy Velthuis

Skybuck said:
I made new news account.

I think this solves the problem for now.

Kinda sux how switching news server fucks up an outlook express
account

Get a real newsreader.
 
S

Skybuck Flying

Evenbit said:
Yes, the Slashdot thread is an interesting read.

Have you ever played Core Wars? Creating a 'Memory Array Redcode
Simulator' in Delphi might be an interesting exercise!

http://en.wikipedia.org/wiki/Core_War
http://en.wikipedia.org/wiki/Redcode

I tried WinCore.

It seems it's not good enough to write self modifieing programs.

The programs can only be writing in "red code" assembler.

It seems impossible to write binary programs or to have the program generate
it's own instructions.

The problem seems to be WinCore does not follow the original red code
specification.

The only self modieing program which seems to work is:

mov 0, 1

However if I tried to write the binary version of it:

1, 0, 1

or

101

It does not compile.

When looking at the object code. Mov seems to be translated into something
else than '1' ?

SHIT that's what it is ;)

Bye,
Skybuck.
 
S

Skybuck Flying

Oh wait,

Now I understand why mov 0, 1 works.

0 represent the current instruction which is itself.

Apperently it is allowed to copy instructions to somewhere else :)

However is it also possible to modify the instructions itself I wonder ?

Can I for example change instruction:

mov 0, 1

to Say

mov 0, 1000 ?

By self modification ? ;)

(Doesn't seem like it ?)

Bye,
Skybuck.
 
S

Skybuck Flying

Well mov 0, 1 probably works with constants.

If the constants are replaced with a memory address...

Then the memory address functions as a pointer.

So if the contents at the pointer^ change... then the instruction can behave
differently.

So while the instruction encoding itself can not be changed as least via
pointers the same kind of more or less same behaviour can be achieved I
think ;)

Probably something like:

mov 0, @Destination

change @destination to something else.

copy mov instruction to somewhere else...

Unless ofcourse @destination is not absolute... but relative... then it
becomes a problem again possibly ;)

Bye,
Skybuck.
 
Top