From 2173d3fdeffc0da5dde2c063a2ed0a90f58dc4e1 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 15 May 2016 23:19:42 +0200 Subject: Initial --- .gitignore | 2 + solve.cpp | 266 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test.sh | 20 +++++ 3 files changed, 288 insertions(+) create mode 100644 .gitignore create mode 100644 solve.cpp create mode 100755 test.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd13184 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +solve +tests/*.tmp diff --git a/solve.cpp b/solve.cpp new file mode 100644 index 0000000..0107521 --- /dev/null +++ b/solve.cpp @@ -0,0 +1,266 @@ +#include +#include +#include +#include +#include + +using namespace std; + + +class Board{ + int8_t *bd; + + inline int8_t& operator[](int i){return bd[i];} + inline int8_t& at(int x,int y,bool tr=false){ + if(tr)return bd[S*x+y]; + else return bd[S*y+x]; + } + + string row(int i,bool tr){return (tr?"column ":"row ")+to_string(i+1);} + string column(int i,bool tr){return (tr?"row ":"column ")+to_string(i+1);} + string pos(int x,int y,bool tr){return "("+to_string(tr?y+1:x+1)+","+to_string(tr?x+1:y+1)+")";} + + bool solvefullrows(bool tr){ + bool changed=false; + for(int y=0;y "< 1"; + } + cerr< 0"; + } + cerr< "< "< "< "<0&&x1&&at(x-2,y,tr)!=-1&&at(x-2,y,tr)==at(x-1,y,tr))opp=at(x-1,y,tr); + else if(x "<=3){ + cerr<<"Trit verification failure at "<>(istream &is,Board &bd); + friend ostream& operator<<(ostream &os,const Board &bd); +}; + +istream& operator>>(istream &is,Board &bd){ + char c; + for(int i=0;i>c; + if(c=='0')bd[i]=0; + else if(c=='1')bd[i]=1; + else if(c=='.'||c=='_')bd[i]=-1; + else { + cerr<<"Invalid char inputted: '"<>S; + Board bd(S); + cin>>bd; + cerr<"$tmpf" 2>/dev/null; then + echo "\x1B[33mERROR\x1B[0m solve returned $?" + fi + total=$((total+1)) + if ! diff "$tmpf" "$outf" >/dev/null; then + echo "failure on $inf" + else + rm "$tmpf" + correct=$((correct+1)) + fi +done +if test $correct -eq $total; then printf "\x1B[33mOK"; else printf "\x1B[31mFAILURE"; fi +printf "\x1B[0m: %d/%d\n" "$correct" "$total" -- cgit v1.2.3