aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--charm.cpp91
-rwxr-xr-xcompetition.py7
-rwxr-xr-xfullcompTabMT.sh2
3 files changed, 45 insertions, 55 deletions
diff --git a/charm.cpp b/charm.cpp
index 56af6c5..45b4f65 100644
--- a/charm.cpp
+++ b/charm.cpp
@@ -44,7 +44,7 @@ public:
grid[S*(S-1)+i]=2;
}
}
- int moved(int at,int dir){
+ int moved(int at,int dir) const{
int x=at%S,y=at/S,x2,y2;
while(true){
x2=x+index_deltas[dir][0];
@@ -87,7 +87,7 @@ public:
undomove(oldneuidx,mv.neudir);
return true;
}
- void print(void){
+ void print(void) const{
int x,y;
if(should_flip_board){
for(y=S-1;y>=0;y--){
@@ -101,59 +101,27 @@ public:
}
}
}
-};
-
-
-int scorefor(const Board &bd){
- int i,score=0;
- for(i=0;i<S*S;i++){
- if(bd.grid[i]==1)score+=i/S;
- else if(bd.grid[i]==2)score-=i/S;
- else if(bd.grid[i]==3){
- score-=(i/S)*(i/S);
- if(i<S)score+=10000;
- }
- }
- return score;
-}
-
-bool sortscoresfunc(const pair<Move,int> &a,const pair<Move,int> &b){
- return a.second>b.second;
-}
-
-Move calculate_move(Board &bd){
- vector<pair<Move,int>> poss;
- Move m;
- int nd,fr,d;
- int newneu;
- int score,oldneuidx;
- //bd.print();
- for(nd=0;nd<8;nd++){
- newneu=bd.moved(bd.neuidx,nd);
- if(newneu==bd.neuidx)continue;
- for(fr=0;fr<S*S;fr++){
- if(bd.grid[fr]!=1)continue;
- //cerr<<"fr="<<fr<<endl;
- for(d=0;d<8;d++){
- m.neudir=nd;
- m.from=fr;
- m.dir=d;
- if(bd.isvalid(m)){
- oldneuidx=bd.neuidx;
- bd.move(oldneuidx,m.neudir,newneu);
- bd.move(m.from,m.dir);
- score=scorefor(bd);
- bd.undomove(m.from,m.dir);
- bd.undomove(oldneuidx,m.neudir);
- poss.push_back({m,score});
+ vector<Move> generate_moves(void){
+ vector<Move> poss;
+ Move m;
+ int nd,fr,d;
+ int newneu;
+ for(nd=0;nd<8;nd++){
+ newneu=moved(neuidx,nd);
+ if(newneu==neuidx)continue;
+ for(fr=0;fr<S*S;fr++){
+ if(grid[fr]!=1)continue;
+ for(d=0;d<8;d++){
+ m.neudir=nd;
+ m.from=fr;
+ m.dir=d;
+ if(isvalid(m))poss.push_back(m);
}
}
}
+ return poss;
}
- sort(poss.begin(),poss.end(),sortscoresfunc);
- for(auto p : poss)cerr<<p.first.str()<<": "<<p.second<<endl;
- return poss[ipow(rand()%(poss.size()/2+1),2)/(poss.size()/2+1)].first;
-}
+};
inline int flip_index(int idx){
@@ -163,7 +131,7 @@ inline int flip_dir(int dir){
return dir==-1?-1:(dir+4)%8;
}
-Move protocol_get_move(void){
+inline Move protocol_get_move(void){
Move m;
char c=cin.peek();
if(c=='q'||c=='Q')exit(0);
@@ -179,7 +147,7 @@ Move protocol_get_move(void){
return m;
}
-void protocol_put_move(ostream &s,Move m){
+inline void protocol_put_move(ostream &s,Move m){
if(should_flip_board){
s<<flip_dir(m.neudir)<<' '<<flip_index(m.from)<<' '<<flip_dir(m.dir)<<endl;
} else {
@@ -187,6 +155,8 @@ void protocol_put_move(ostream &s,Move m){
}
}
+Move calculate_move(Board &bd);
+
int main(void){
Board bd;
Move mv;
@@ -234,3 +204,18 @@ int main(void){
}
return 0;
}
+
+
+
+class Node{
+ Node *firstchild,*nextsibling;
+ uint8_t flags;
+#define NFLAG_PLAYER (0x1)
+#define NFLAG_IS_TERMINAL (0x2)
+#define NFLAG_TERMINAL_PLAYER (0x4)
+ uint8_t board[7]; //7*8=56; 5*5*2=50 (5*5=25 cells, 2 bits per cell); of last byte only 2 bits used
+};
+
+Move calculate_move(Board &bd){
+ static Node root;
+}
diff --git a/competition.py b/competition.py
index 7c48846..9d3c15a 100755
--- a/competition.py
+++ b/competition.py
@@ -18,6 +18,8 @@ Options:
import os,sys,subprocess,shlex,re,time
+MAXTIMELIMIT=None #in seconds
+
S=5
PNONE=0
PP1=1
@@ -282,14 +284,15 @@ while True:
if len(line)>0:
break
time.sleep(0.1)
+ if MAXTIMELIMIT==None: continue
timeoutfail=False
if player==1:
p1totaltime+=0.1
- if p1totaltime>=50:
+ if p1totaltime>=MAXTIMELIMIT:
timeoutfail=True
else:
p2totaltime+=0.1
- if p2totaltime>=50:
+ if p2totaltime>=MAXTIMELIMIT:
timeoutfail=True
if timeoutfail:
print("P"+str(player)+" timed out!")
diff --git a/fullcompTabMT.sh b/fullcompTabMT.sh
index 53c442e..c592c00 100755
--- a/fullcompTabMT.sh
+++ b/fullcompTabMT.sh
@@ -156,5 +156,7 @@ EOF
ponei=$((ponei + 1))
done
+echo COMPETITION START >competition.log
+
#run the competition in threads
find competitionstubs -type f -name 'game_*' | xargs -P$num_cores -n1 -- bash