#197 (117 in gold) #1 in India
First of all a hail to all of those CG staff who organised such a big contest in a very good manner,really a hatsoff to all of em’.
This game was quite easy if you think and even easy to start but is hard to master it, On the first day of contest i was confused between many algos that what should i use Minimax, simulation, BFS, Genetic algorithm, MCTS,etc. To be true i think all of these algorithm would have worked good but i need anyone so i choose my favourite - Simulation, As already it was night in India so i slept without getting bronze, On next morning I made bronze and then i started writing my Simulation code. I have 5 classes at all -
class timeout;
class inv;//inventory
class gamestate;
class action;
class player;
class sim;
So, after making all classes i started by sorting my moves and opponent moves which is simple just remove ‘OPPONENT_CAST’ moves from your input and saved them in the array
#CHECKING VALIDITY OF MOVES
So validating that this move playable or not at particular gamestate looks something like this -
if (action.type == REST) return true; //not neccesary to check if REST is valid action or not
else if (action.type == LEARN && me.inventory.inv0 >= action.tomeIndex) return true;
else if (action.type == BREW &&(c.inventory.inv0 >= -action.d0 && c.inventory.inv1 >= -action.d1&& c.inventory.inv2 >= -action.d2 && c.inventory.inv3 >= -action.d3&& c.inventory.total()+action.d0+action.d1+action.d2+action.d3 <=10)) return true;
else if (action.type == CAST &&(c.inventory.inv0 >= -action.d0 && c.inventory.inv1 >= -action.d1&& c.inventory.inv2 >= -action.d2 && c.inventory.inv3 >= -action.d3&& action.castable == 1)) return true;
else return false;
after this i developed the game engine ,Next day it was ‘DIWALI’ in India(One of major festival in India) so i wasn’t able to code that day so on next morning i.e. 15th Nov’s morning i made my simulation ready, But too much bugs i was nearly 2000 with my heuristic and got 1200 with that buggy simulation then i felt nervous that what would happen if i won’t be able to fix my code and started fixing bugs and then on that day i ended on 729th and on Next day silver was going to open so i fixed some more bugs and reached 400 and after silver opening i fixed nearly every bug.
#WHATS NEXT??
so, after lot of bug fixing + optimization i read rules again and bingo i forgot to add repeatable casts in my scope i was treating them as non repeatable cast and fixing that gave me much
Now lets talk about affect each action on the gamestate-
#BREW -
Brew is basically to make a potion so just add its price to your inventory score and mark it as visited so that you won’t choose that action again in same sim
#LEARN
I found learning the most complex action of all so basically deltas and repeatable value given in input for learn action are deltas and repeatable value of CAST spell you will learn so first of all subtract tomeIndex from your tier-0 ingredients then make new valid CAST action deltas and repeatable value same as LEARN action then add taxCount in your tier-0 ingredients basically min(taxCount, left_space_in_inevntory)
#CAST
So for cast simply do -
me.inventory.inv0 += d0;
me.inventory.inv1 += d1;
me.inventory.inv2 += d2;
me.inventory.inv3 += d3;
castable = 0;//mark it visited
#REST
its the simplest action in this game so simply make castable = 1 of all your CAST action
#WAIT
Really, just ignore it
Now i will tell you about backbone of simulation (evaluation system)
#EVALUATING EACH ITERATION
in each depth when i apply one action in gamestate if that action.type == BREW then value += MAX_DEPTH - depth
and after completing my one iteration i evaluate it more by -
value += my money
value += inv1 *2
value += inv2 * 3
value += inv3 * 4
But on last 2 days my rank broked a lot so changed to beam search with same eval.
this is all i have for my code, With more optimization and better eval can give you better rank.
Thanks