Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Find the best move in Unspeakable Words - written in setlX (http://randoom.org/Software/SetlX)
- winProbabilityForMove := procedure(wordLength, lives, score, opponentLives, opponentScore) {
- if (lives <= 0) {
- return 0.0;
- }
- probKeepLives := (21 - wordLength) / 20;
- if (wordLength + score >= 100) {
- if (lives > 1) {
- return 1.0;
- } else {
- return 1.0*probKeepLives;
- }
- }
- [_,probLoseGivenKeepLives] := bestMove(opponentLives, opponentScore, lives, score + wordLength);
- probWinGivenKeepLives := 1 - probLoseGivenKeepLives;
- probLoseLife := 1 - probKeepLives;
- [_,probLoseGivenLoseLife] := bestMove(opponentLives, opponentScore, lives - 1, score + wordLength);
- probWinGivenLoseLife := 1 - probLoseGivenLoseLife;
- return 1.0 * probKeepLives * probWinGivenKeepLives + probLoseLife * probWinGivenLoseLife;
- };
- bestMove := cachedProcedure(lives, score, opponentLives, opponentScore) {
- bestWordLength := 0;
- bestWinProb := 0;
- for (wordLength in [1..min({20,100-score})]) {
- winProb := winProbabilityForMove(wordLength, lives, score, opponentLives, opponentScore);
- if (winProb >= bestWinProb) {
- bestWordLength := wordLength;
- bestWinProb := winProb;
- }
- }
- return [bestWordLength, bestWinProb];
- };
- for (lives in [1..5]) {
- for (score in [99,98..0]) {
- for (l2 in [1..5]) {
- for (s2 in [99,98..0]) {
- print(lives+" "+score+" "+l2+" "+s2+" "+ bestMove(lives, score, l2, s2));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement