p^3 switchers.

G

Guest

Guest
Archived from groups: rec.games.corewar (More info?)

I'm having troubles getting them.
I understand exactly how they work, but not how to write them.

I get that you pick values so that when modded by others, they decode
to the right state...but I looked at CW#70, which explains how to
write it...can't understand it.

Several questions:
Can I make an arbitrary table? For example, let's say I've got 10
states.
Can I make a p^3 that'll implement any possible switch between them?
If so, how do I make it? Let's say I've got the following (simple)
table.
state 0: strat 1. Win 1, loss 2, tie 0
state 1: strat 1. Win 0, loss 4,tie 3
state 2: strat 2. Win 4, loss 3, tie 2
state 3: state 3. Win 0, loss 5, tie 3
state 4: strat 3. win 4,loss 3, tie 5
state 5: strat 4. Win 5, loss 0, tie 4

Can someone walk me through writing a P^3 table to implement that
switch?
 
Archived from groups: rec.games.corewar (More info?)

wackoyacko2000@yahoo.com (Andrew Hunter) wrote in message news:<112f3b73.0406070831.4f034530@posting.google.com>...
> I'm having troubles getting them.
> I understand exactly how they work, but not how to write them.
>
> I get that you pick values so that when modded by others, they decode
> to the right state...but I looked at CW#70, which explains how to
> write it...can't understand it.
>
> Several questions:
> Can I make an arbitrary table? For example, let's say I've got 10
> states.

Yes. If memory serves, for an 8000 line core, and for less
than 18 states you can realize any table.

> Can I make a p^3 that'll implement any possible switch between them?
> If so, how do I make it? Let's say I've got the following (simple)
> table.
> state 0: strat 1. Win 1, loss 2, tie 0
> state 1: strat 1. Win 0, loss 4,tie 3
> state 2: strat 2. Win 4, loss 3, tie 2
> state 3: state 3. Win 0, loss 5, tie 3
> state 4: strat 3. win 4,loss 3, tie 5
> state 5: strat 4. Win 5, loss 0, tie 4
>
> Can someone walk me through writing a P^3 table to implement that
> switch?


PSTATE equ 123

ldp.a #0 , in
ldp.a #PSTATE , table
mod.ba *in , table
stp.b *table , #PSTATE

table jmp } 0, # key0; 0: strat 1. Win 1, loss 2, tie 0
spl # strat_1, # key1; 1: strat 1. Win 0, loss 4, tie 3
spl # strat_2, # key2; 2: strat 2. Win 4, loss 3, tie 2
spl # strat_3, # key3; 3: state 3. Win 0, loss 5, tie 3
spl # strat_3, # key4; 4: strat 3. win 4, loss 3, tie 5
spl # strat_4, # key5; 5: strat 4. Win 5, loss 0, tie 4

; must have non-zero b-field in
; the previous cell
; set # of states N = 7 (ignoring risk of brainwash)

in nop # strat_1, 5 ; N - 2, loss
nop # 0 , 6 ; N - 1, win
nop # 0 , 7 : N , tie

;Now we just need to solve for the keys. For key0, we have
;3 equations:
; key0 % 5 == 2
; key0 % 6 == 1
; key0 % 7 == 0
; There's an elegant formula.... alternatively just try
; every possibility between 0 and CORESIZE-1


int lazy(int win, int loss, int tie, int N)
{
int i, key; //N is number of states


key = -1;
for (i = 0;i < 8000; i++)
{
if ( ( i % (N - 2) == loss ) &&
( i % (N - 1) == win ) &&
( i % (N - 0) == tie ) )
{
key = i;
break;
}
}
printf("key = %d \n", key);
if (key == -1) {printf("FAILED\n");}
return(key);
}

The answer for key0 is 7

Dave Hillis
 
Archived from groups: rec.games.corewar (More info?)

My previous post should have had N = 21.
You obviously understand it well enough to
have constructed a perverse table :)

key0 = 21
key1 = 5400
key2 = 3404
key3 = 1620
key4 = 7964
key5 = 6745

Dave Hillis
 
Archived from groups: rec.games.corewar (More info?)

The value of N must be 21. Sorry if this shows up twice. And brainwash
protection would be a good addition.


> ; must have non-zero b-field in
> ; the previous cell
> ; set # of states N = 7 (ignoring risk of brainwash)
>
> in nop # strat_1, 5 ; N - 2, loss
> nop # 0 , 6 ; N - 1, win
> nop # 0 , 7 : N , tie
>
> ;Now we just need to solve for the keys. For key0, we have
> ;3 equations:
> ; key0 % 5 == 2
> ; key0 % 6 == 1
> ; key0 % 7 == 0
> ; There's an elegant formula.... alternatively just try
> ; every possibility between 0 and CORESIZE-1
>
>
> int lazy(int win, int loss, int tie, int N)
> {
> int i, key; //N is number of states
>
>
> key = -1;
> for (i = 0;i < 8000; i++)
> {
> if ( ( i % (N - 2) == loss ) &&
> ( i % (N - 1) == win ) &&
> ( i % (N - 0) == tie ) )
> {
> key = i;
> break;
> }
> }
> printf("key = %d \n", key);
> if (key == -1) {printf("FAILED\n");}
> return(key);
> }

Dave Hillis