Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var TARGET_ARRANGEMENT_RAIL = [
- [3,5,6,1,6,7,6,2,8],
- [3,5,6,4,6,7,6,2,8],
- [1,6,7,6,2,8,3,5,6],
- [4,6,7,6,2,8,3,5,6],
- [6,2,8,3,5,6,1,6,7],
- [6,2,8,3,5,6,4,6,7]
- ];
- var TARGET_COLOURS_RAIL = colour_band([6, 5, 2]);
- var rail_miners = {
- likely_nest: function(colours) {
- var bestScore = 0;
- TARGET_ARRANGEMENT_RAIL.forEach(function (arrangement) {
- ROTATIONS.forEach(function (rot){
- var score = 0;
- for(var i = 0; i < 9; i++) {
- score += arrangement[i] == view[rot[i]].color?1:0;
- }
- if(score > bestScore) {
- bestScore = score;
- }
- });
- });
- if(bestScore >= 6) {
- return true;
- }
- return false;
- },
- likely_victim: function(victim_pos) {
- var c0 = TARGET_COLOURS_RAIL.next(WHITE);
- var c1 = TARGET_COLOURS_RAIL.next(c0);
- if(view[victim_pos].color !== c0) {
- return false;
- }
- for(var i = 0; i < 9; ++ i) {
- if(i !== victim_pos && near(i, victim_pos) && view[i].color === c1) {
- return true;
- }
- }
- return false;
- },
- follow_victim: function(me, buddies, colours, victim_pos) {
- if(me.type === THIEF && !buddies[QUEEN]) {
- // Queen may be on other side of victim; try orbiting to find her
- return try_all_angles([
- (rot) => ((victim_pos === rot[1]) ? {cell: rot[0]} : null),
- (rot) => ((victim_pos === rot[0]) ? {cell: rot[3]} : null)
- ]);
- }
- if(me.type === QUEEN && !buddies[THIEF] && me.food > 0) {
- // Make a buddy to help us steal
- return best_of([
- try_all_cells((i) => (near(i, victim_pos) ? {cell: i, type: THIEF} : null), true),
- try_all_cells((i) => ({cell: i, type: THIEF}), true)
- ]);
- }
- return best_of([
- // Ziggurat will try to drown us in workers; make sure we have plenty
- // of our own (but only if it's worth it)
- (view[victim_pos].ant.food > 4) &&
- try_all_cells((i) => (near(i, victim_pos) ? {cell: i, type: THIEF} : null), true),
- // Continue to steal and get fat
- NOP
- ]);
- },
- find_victim: function(me, buddies, colours) {
- var current = view[CENTRE].color;
- // Easier to navigate alone, and thief reaching queen first would be a
- // disaster, so the thief just gives up.
- if(me.type === THIEF) {
- return go_anywhere;
- }
- var target = colour_band_prev(TARGET_COLOURS_RAIL, current);
- var antitarget = colour_band_prev(TARGET_COLOURS_RAIL, target);
- var ret = best_of([
- try_all_cells((i) => ((i % 2 == 1 && view[i].color == target && view[8-i].color == antitarget) ? {cell: i} : null)),
- //try_all_cells((i) => ((view[i].color == current) ? {cell: i} : null)),
- // Random walk to avoid getting stuck
- {cell:4}
- ]);
- if(ret == null || ret.cell == 4) {
- var numAnts = 0;
- for(var na = 0; na < 9; na++) {
- if(view[na].ant != null) numAnts++;
- }
- if(numAnts == 1) ret = go_anywhere;
- }
- return ret;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement