summaryrefslogtreecommitdiff
path: root/leavecalc.c
diff options
context:
space:
mode:
authorJason Katz-Brown <jason@airbnb.com>2013-08-25 02:17:13 -0700
committerJason Katz-Brown <jason@airbnb.com>2013-08-25 02:17:13 -0700
commit9306cb60c32082c5403931de0823a9fd5daa196c (patch)
treeca1b6eb695fdf3f0c2294e92416b272164bae642 /leavecalc.c
parent8fb2c681cecc01b46b0f4ba02d5cc177c4747b1c (diff)
Initial git commit.
Diffstat (limited to 'leavecalc.c')
-rwxr-xr-xleavecalc.c171
1 files changed, 171 insertions, 0 deletions
diff --git a/leavecalc.c b/leavecalc.c
new file mode 100755
index 0000000..89a1ed6
--- /dev/null
+++ b/leavecalc.c
@@ -0,0 +1,171 @@
+// old, unused reference code
+#include <stdio.h>
+#include <string>
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <vector>
+#include <map>
+
+#include "board.h"
+#include "bag.h"
+#include "util.h"
+#include "generator.h"
+
+using namespace std;
+using namespace Utility;
+
+Generator G;
+
+Board randboard(string leave, int minleft, int maxleft) {
+
+ int leaveatmost = minleft + rand()%(maxleft - minleft);
+
+ Board B;
+ B.init();
+ Bag S;
+ Rack dummy;
+ S.fill(dummy, leave);
+
+ Rack R[2];
+ S.refill(R[0]);
+ S.refill(R[1]);
+
+ G.setboard(B);
+
+ for (int i = 0; (i < 25) && !S.empty(); i++) {
+ for (int j = 0; j < 2; j++) {
+
+ if (S.size() <= leaveatmost) {
+ return G.getboard();
+ }
+
+ // cout << S << endl;
+ // cout << R << endl;
+
+ G.setrack(R[j]);
+
+ bool canexch = false;
+
+ if (S.size() >= 7) {
+ canexch = true;
+ }
+
+ Move M = G.findstaticbest(canexch);
+
+ cout << "randboard M: " << R[j] << " " << M << " " << M.score << " " << M.equity << endl;
+
+ if (M.action == Place) {
+ G.makemove(M);
+
+ R[j] -= M;
+ S.refill(R[j]);
+ }
+ else if (M.action == Exchange) {
+ S.exch(M, R[j]);
+ }
+
+ // cout << B << endl;
+
+ R[j] -= M;
+ S.refill(R[j]);
+ }
+ }
+
+ return G.getboard();
+}
+
+
+void sim(Board orig, string leave, int n) {
+ Bag origS;
+ for (int i = 0; i < 15; i++) {
+ for (int j = 0; j < 15; j++) {
+ string c = "";
+ if (isalpha(orig.letters[i][j])) {
+ if (isupper(orig.letters[i][j])) {
+ c += orig.letters[i][j];
+ }
+ else {
+ c = "?";
+ }
+ }
+ Rack dummy;
+ origS.fill(dummy, c);
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ Board B = orig;
+ Rack R[2];
+ Bag S = origS;
+ // cout << "S: " << S << endl;
+ S.fill(R[0], leave);
+ // cout << "R[0] before it gets filled: " << R[0] << endl;
+ S.refill(R[0]);
+ S.refill(R[1]);
+ Move M[3];
+
+ G.setboard(B);
+
+ for (int j = 0; j < 3; j++) {
+ G.setrack(R[j % 2]);
+ cout << "R[" << j % 2 << "]: " << R[j % 2] << endl;
+
+ bool canexch = false;
+
+ if (S.size() >= 7) {
+ canexch = true;
+ }
+
+ M[j] = G.findstaticbest(canexch);
+
+ if (M[j].action == Place) {
+ B.makemove(M[j]);
+ G.makemove(M[j]);
+
+ R[j % 2] -= M[j];
+ S.refill(R[j % 2]);
+ }
+ else if (M[j].action == Exchange) {
+ S.exch(M[j], R[j % 2]);
+ }
+
+ cout << "M[" << j << "]: " << M[j] << " " << M[j].score << " " << M[j].equity << endl;
+ cout << B << endl;
+
+ R[j % 2] -= M[j];
+ S.refill(R[j % 2]);
+ }
+ }
+}
+
+int main(int argc, char** argv) {
+ //G.loaddawg("twl15new.anadawg");
+ G.loaddawg("ods.dawg");
+ G.loadsyn2("syn2");
+
+ cout << "loaded dawg" << endl;
+
+ srand(time(NULL));
+
+ string leave;
+
+ if (argc < 2) {
+ leave = "";
+ }
+ else {
+ leave = argv[1];
+ }
+
+ for (int i = 0; i < leave.length(); i++) {
+ leave[i] = toupper(leave[i]);
+ }
+
+ cout << "leave: " << leave << endl;
+
+ for (int i = 0; i < 1000; i++) {
+ Board B = randboard(leave, 0, 72);
+ cout << B << endl;
+ sim(B, leave, 10);
+ }
+}