From 2173d3fdeffc0da5dde2c063a2ed0a90f58dc4e1 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 15 May 2016 23:19:42 +0200 Subject: Initial --- solve.cpp | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 solve.cpp (limited to 'solve.cpp') 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<