public override string Turn(Game current) { String returnString = "Pass"; Tile t1 = new Tile(current.ReturnTile(0)); Tile t2 = new Tile(current.ReturnTile(1)); Tile t3 = new Tile(current.ReturnTile(2)); Tile[] options = new Tile[] { t1, t2, t3 }; bool[] canBePlaced = new bool[] { false, false, false }; for (int i = 0; i < 3; i++) // ugly brute force check that a tile can be placed { if (options[i].ReturnCost() < this.GetButtons()) { for (int r = 0; r < 4; r++) { for (int x = -1; x < 10; x++) { for (int y = -1; y < 10; y++) { if (this.GetGrid().tryTile(x, y, options[i])) { canBePlaced[i] = true; goto NextTile; } } } options[i].rotate(1); } } NextTile :; } //determine what tile to place int numCanBePlaced = 0; int toBePlaced = -1; foreach (bool b in canBePlaced) { if (b) { numCanBePlaced++; } } switch (numCanBePlaced) { case 0: return(returnString); case 1: int i = 0; foreach (bool b in canBePlaced) { if (b) { toBePlaced = i; } i++; } break; case 2: //if more than 1 choice then ppt case 3: int j = 0; float best = 0; float c; bool tie = false; foreach (bool b in canBePlaced) { if (b) { if (this.GetTime() > TimeThreshhold) //make variable { if (options[j].ReturnButtons() > best) { toBePlaced = j; best = options[j].ReturnButtons(); tie = false; } else if (options[j].ReturnButtons() == best) { tie = true; } else { canBePlaced[j] = false; } } else { } } j++; } j = 0; if (this.GetTime() <= TimeThreshhold || tie == true) { foreach (bool b in canBePlaced) { if (b) { c = 0; foreach (bool t in options[j].returnshape()) //points for tile size { if (t) { c += 2; } } c += options[j].ReturnButtons() * current.ButtonsLeft(this.GetTime()); //points for the buttons c -= options[j].ReturnCost(); //cost c = c / options[j].ReturnTime(); if (c > best) { toBePlaced = j; best = c; } } j++; } } break; default: Console.WriteLine("error"); Console.ReadLine(); break; } float co = 0; //points for tile size foreach (bool t in options[toBePlaced].returnshape()) { if (t) { co += 2; } } if (1 >//if passing is worth more than the tile ((options[toBePlaced].ReturnButtons() * current.ButtonsLeft(this.GetTime()) - (options[toBePlaced].ReturnCost()) + (co)) / options[toBePlaced].ReturnTime()) ) { return("Pass"); } t1 = new Tile(current.ReturnTile(0));//reset tile manipulations t2 = new Tile(current.ReturnTile(1)); t3 = new Tile(current.ReturnTile(2)); options = new Tile[] { t1, t2, t3 }; //place that tile (more ugly brute force) for (int r = 0; r < 4; r++) { for (int x = -1; x < 10; x++) { for (int y = -1; y < 10; y++) { if (this.GetGrid().tryTile(x, y, options[toBePlaced])) { returnString = toBePlaced + "/" + y + "/" + x + "/R" + r; //if (f == 1) // { //returnString += "/F"; //} return(returnString); } } } options[toBePlaced].rotate(1); } return(returnString); }