prisoners dilema

General FreeBASIC programming questions.
bluatigro
Posts: 597
Joined: Apr 25, 2012 10:35
Location: netherlands

prisoners dilema

old programming problem :
2 prisoners are catched for a crime
thet are set seperately
they face this dilema :
if one is a rat then hy goes free and the other gets 5 year
if two are rats then they get 3 year
if two are silent then they get one year

write a programe that minmises the years in prison against other programs

error :
in the orignal try tit for tat won
in my try not .

Code: Select all

'' bluatigro 13 sept 2018
'' prisoners dilema sim

const as integer rat = 1    '' always rat out
const as integer silent = 0 '' always be silent
const as integer t4t = 2
'' tit fot tat :
'' begin silent
'' then copy reply other
const as integer t4t2 = 3
'' tit for tat 2
'' begin silent
'' then copy reply other
'' somtimes be silent
dim as integer r( 4 ) , i , j , k , a , b , tel( 4 )

for k = 0 to 1000
for i = 0 to 3
for j = 0 to 3
select case i
case rat
a = rat
case silent
a = silent
case t4t
a = r( j )
case t4t2
a = r( j )
if rnd < .3 then a = silent
end select
select case j
case rat
b = rat
case silent
b = silent
case t4t
b = r( i )
case t4t2
b = r( i )
if rnd < .3 then b = silent
end select
r( i ) = b
if a = silent then
if b = silent then
tel( i ) += 1
else
tel( i ) += 5
end if
else
if b = silent then
else
tel( i ) += 3
end if
end if
next j
next i
next k
print "silent : " + str( tel( 0 ) )
print "rat    : " + str( tel( 1 ) )
print "t4t    : " + str( tel( 2 ) )
print "t4t2   : " + str( tel( 3 ) )
sleep