SHARE
TWEET

Unspeakable Words Source Code

a guest Mar 8th, 2014 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Find the best move in Unspeakable Words - written in setlX (http://randoom.org/Software/SetlX)
  2.  
  3. winProbabilityForMove := procedure(wordLength, lives, score, opponentLives, opponentScore) {
  4.         if (lives <= 0) {
  5.                 return 0.0;
  6.         }
  7.         probKeepLives := (21 - wordLength) / 20;
  8.         if (wordLength + score >= 100) {
  9.                 if (lives > 1) {
  10.                         return 1.0;
  11.                 } else {
  12.                         return 1.0*probKeepLives;
  13.                 }
  14.         }
  15.         [_,probLoseGivenKeepLives] := bestMove(opponentLives, opponentScore, lives, score + wordLength);
  16.          probWinGivenKeepLives := 1 - probLoseGivenKeepLives;
  17.         probLoseLife := 1 - probKeepLives;
  18.         [_,probLoseGivenLoseLife] := bestMove(opponentLives, opponentScore, lives - 1, score + wordLength);
  19.          probWinGivenLoseLife := 1 - probLoseGivenLoseLife;
  20.         return 1.0 * probKeepLives * probWinGivenKeepLives + probLoseLife * probWinGivenLoseLife;
  21. };
  22.  
  23. bestMove := cachedProcedure(lives, score, opponentLives, opponentScore) {
  24.         bestWordLength := 0;
  25.         bestWinProb := 0;
  26.         for (wordLength in [1..min({20,100-score})]) {
  27.                 winProb := winProbabilityForMove(wordLength, lives, score, opponentLives, opponentScore);
  28.                 if (winProb >= bestWinProb) {
  29.                         bestWordLength := wordLength;
  30.                         bestWinProb := winProb;
  31.                 }
  32.         }
  33.         return [bestWordLength, bestWinProb];
  34. };
  35.  
  36. for (lives in [1..5]) {
  37.         for (score in [99,98..0]) {
  38.                 for (l2 in [1..5]) {
  39.                         for (s2 in [99,98..0]) {
  40.                                 print(lives+" "+score+" "+l2+" "+s2+" "+ bestMove(lives, score, l2, s2));
  41.                         }
  42.                 }
  43.         }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top