Question
How to solve these codes with python? # Game setting constants SECTION_LENGTH = 3 ANSWER = 'CATDOGFOXEMU' # Move constants SWAP = 'S' ROTATE =
How to solve these codes with python?
# Game setting constants SECTION_LENGTH = 3 ANSWER = 'CATDOGFOXEMU'
# Move constants SWAP = 'S' ROTATE = 'R' CHECK = 'C'
is_valid_move (str) -> bool | The parameter is a string that may or may not be a valid move in the game. This function should return True if and only if the parameter represents a valid move, i.e. it matches one of the three move constants. |
is_valid_section (int) -> bool | The parameter is an int that may or may not be a valid section number. This function should return True if and only if the parameter represents a section number that is valid for the current answer string and section length. For example, if the answer string is 'wordlockgame' and the section length is 4, then this function should return True for the ints 1, 2, and 3, and False for all other ints. |
check_section (str, int) -> bool | The first parameter is the game state (i.e. the current state of the scrambled string), and the second parameter is a valid section number. This function should return True if and only if the specified section in the game state matches the same section in the answer string. That is, if the specified section has been correctly unscrambled. |
change_state (str, int, str) -> str | The first parameter represents the game state, the second parameter is the section number of the section to be changed, and the third parameter is the move to be applied to the string. The move will be one of SWAP or ROTATE. This function should return a new string that reflects the updated game state after applying the given move to the specified section. For example, if the section length is 4, and this function is called change_state ('wrdokoclgmae', 2, 'S'), then the function should return 'wrdolockgmae'. |
get_move_hint (str, int) -> str | In this function only, you may assume a fixed section length of 3. The first parameter represents a game state, and the second parameter represents the number of a section in the game state that is not yet unscrambled. This function should return a move (either SWAP or ROTATE) that will help the player rearrange the specified section correctly. Use your creativity here, but make sure to give hints that if used in progression, should never produce the same game state twice. For example, always telling the user to play SWAP on a section 'ATC' each round will cause that section of the game state to go back and forth between 'ATC' and 'CTA', and never to get to the answer ('CAT'). If a player repeatedly follows your hints, they should be guaranteed to end up solving the game. Hint: Consider the cases in which SWAP is a bad move to make. Note that this function may not work if SECTION_LENGTH is anything other than 3. |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started