Created
August 5, 2016 10:10
-
-
Save increpare/a7c2a8cd26648153e913c2dd899ba805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"log" | |
"time" | |
) | |
var cards = [][]int{ | |
{0,0,0,0}, | |
{1,0,0,0}, | |
{0,1,0,0}, | |
{0,0,1,0}, | |
{1,1,0,0}, | |
{1,0,1,0}, | |
{0,1,1,0}, | |
{0,0,1,1}, | |
{1,1,1,0}, | |
{1,0,1,1}, | |
{0,1,1,1}, | |
{1,1,1,1}, | |
} | |
var compatibility [][]int | |
func compatible(x []int, y []int) int { | |
if (x[0]<=y[0]&&x[1]<=y[1]&&x[2]<=y[2]&&x[3]<=y[3]) || | |
(x[0]>=y[0]&&x[1]>=y[1]&&x[2]>=y[2]&&x[3]>=y[3]) { | |
return 1 | |
} else { | |
return 0 | |
} | |
} | |
func genCompatibilityMatrix(){ | |
var l = len(cards) | |
compatibility = make([][]int, l) | |
for i:=0; i<l; i++ { | |
compatibility[i] = make([]int,l) | |
} | |
for i:=0; i<l; i++ { | |
compatibility[i][i] = 1 | |
for j:=i+1;j<l;j++ { | |
compatibility[i][j] = compatible(cards[i],cards[j]) | |
compatibility[j][i] = compatibility[i][j] | |
} | |
} | |
} | |
type state struct { | |
top int | |
a int | |
b int | |
playable []int | |
} | |
func genStartingDecks() { | |
var l = len(cards) | |
var result []struct = make([]struct,l*l); | |
for i:=0; i<l; i++ { | |
for j:=i+1; j<l; j++ { | |
var s state | |
s.top=-1 | |
s.a=i | |
s.b=j | |
result[i+l*j]=s | |
playable = make ([]int,l-2) | |
for k=0;k<l-2;k++ { | |
playable[k]=k | |
if k>=j-1 { | |
playable[k]+=2 | |
} else if k>=i { | |
playable[k]++ | |
} | |
} | |
} | |
} | |
return result | |
} | |
func dupstate (s state) state { | |
var result state | |
result.top = s.top | |
result.a=s.a | |
result.b=s.b | |
result.playable = make([]int,len(s.playable)) | |
copy(result.playable,s.playable) | |
return result | |
} | |
func initState () state{ | |
var result state | |
result.top = -1 | |
result.a=-1 | |
result.b=-1 | |
var shuffled = rand.Perm(len(cards)) | |
return result | |
} | |
func isSolid (s state){ | |
return result.a>=0 && result.b>=0 | |
} | |
func solidify(s state) []state { | |
if (s.a==-1&&s.b==-1){ | |
return genStartingDeck() | |
} | |
} | |
func randomInput() []int { | |
var shuffled = rand.Perm(len(cards)) | |
for i:=0; i<len(shuffled); i++ { | |
shuffled[i]=shuffled[i]%2 | |
} | |
return shuffled | |
} | |
func main() { | |
rand.Seed(time.Now().UTC().UnixNano()) | |
log.SetFlags(log.LstdFlags | log.Lshortfile) | |
genCompatibilityMatrix() | |
cs := randomConcreteState() | |
input := randomInput() | |
fmt.Printf("cs: %v\n", cs) | |
fmt.Printf("input: %v\n", input) | |
run(input,&cs) | |
fmt.Printf("output: %v\n", cs) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./gosim.go:61: syntax error: unexpected =, expecting { | |
./gosim.go:62: syntax error: unexpected for, expecting field name or embedded type | |
./gosim.go:63: syntax error: unexpected for, expecting } | |
./gosim.go:79: syntax error: non-declaration statement outside function body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment