This is my solution in Haskell. The "object" containing the function is pretty awkward in Haskell. It would probably be better to just use the makeMove function directly or partially applied.
Quick note: In my exploration of this game, it seems like if the matches remaining at the beginning of your turn is in a specific arithmetic sequence, then you have to rely on the opponent making a mistake. With my bot, this can only happen if the starting number of matches is in this sequence. If this happen, it just picks up as many matches as possible to lose as fast as possible (hence, "Pessimist Bot").
dataBot=Bot{getName::String,getMakeMove::Integer->Integer}makeMove::Integer->Integer->IntegermakeMovelm|m==1=1|m<l+2=m-1|otherwise=letd=minimum[m-z|t<-[1..m],letz=(l+1)*t+1,z<=m]inifd>l||d==0thenl-- Give up, the only way to win is the opponent messes upelsedcreateBot::Integer->Integer->BotcreateBotnl=Bot"Pessimist Bot"$makeMovel
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is my solution in Haskell. The "object" containing the function is pretty awkward in Haskell. It would probably be better to just use the
makeMove
function directly or partially applied.Quick note: In my exploration of this game, it seems like if the matches remaining at the beginning of your turn is in a specific arithmetic sequence, then you have to rely on the opponent making a mistake. With my bot, this can only happen if the starting number of matches is in this sequence. If this happen, it just picks up as many matches as possible to lose as fast as possible (hence, "Pessimist Bot").