Sale!

CSED101 Programming Assignment #1 Solved

Original price was: $35.00.Current price is: $28.00.

Download Details:

  • Name: ASSN1-5icn4d.zip
  • Type: zip
  • Size: 1.12 MB

Category:

Description

5/5 - (1 vote)

 ◼ Problem:

Climbing the stairs of Mukjjipa

(Purpose)

Through this assignment, you will learn how to use conditional statements, loop statements, user-defined functions, and random functions. (Note) (1) Since this assignment is a problem that teaches you how to define and use functions, you will be penalized if you implement the function without defining the function.

The user-defined functions that must be defined and used are explained in the document, so check them and implement them. – The parameters of the user-defined functions that must be defined and used can be freely modified and used. (2) You can use only the contents covered in class up to int, float, bool, str, list, and tuple data types. (3) The output format of the problem should be written as similar as possible to the execution example below for grading.

(Explanation) This game is played by two people, and in this assignment, the computer and the user play. The computer and the user play Mukjjipa on the stairs on the opposite hill and go up or down the stairs according to the rules. At this time, the player who first arrives at the opponent’s starting point wins the game.

The ‘Mukjjipa’ for winning or losing uses the following rules. (1) Determining the right to attack For the rock-paper-scissors game, each player (computer, user) chooses one of scissors, rock, or paper. If both players make the same choice, they continue playing rock-paper-scissors until a winner is determined, and the player who wins the rock-paper-scissors game has the right to attack.

(2) Executing Mukjjipa Players choose one of scissors, rock, or paper. If the shape of the hand of the person with the right to attack matches the shape of the opponent’s hand, the person with the right to attack wins. If the winner is not determined, the person who wins according to the rock-paper-scissors rules in the current situation takes the right to attack.

(3) Determining the right to win and rules for moving on stairs The player who wins Mukjjipa moves on the stairs the number of turns consumed until a winner is determined. 3 I. Starting the game When the program starts, a text for entering the number of stairs is displayed as shown in Figure 1 below and prepares to receive input from the user. However, the number of stairs is limited to 10 to 30. For inputs out of range, re-enter them as in the example below. Inputs other than integers are not considered.

(The red underline in the running example corresponds to user input.) ====================== [Mukjjippa Stair Climb] ======================= ○ ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨▨▨ Please enter the number of stairs for the game. <10 ~ 30> >> Enter the number of stairs for game 7. <10 ~ 30> >> Enter the number of stairs for game 388. <10 ~ 30> >> Figure 1.

If you enter the number of stairs within the range of the game’s initial screen, the screen will be cleared and the screen for playing with the computer will be displayed as in Figure 2. For the implementation of this part, refer to the explanation of ‘Screen Clearing’ in Tips (last page). (All output screens of this assignment are output after clearing the screen if it is specified to do so.

When clearing the screen, no input other than Enter is considered.) Total number of steps: 12 PLAYER: ○ < 0> COMPUTER: ● < 0> ○ ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨ Press Enter to continue… Figure 2.계단이 생성된 화면 예시(12개의 계단을 입력한 경우) ◆ 그림 2의 (1) – 사용자가 입력한 총 계단 수 – PLAYER의 위치를 표시하는 기호 ‘○’와 현재까지 이동한 계단 수 – COMPUTER의 위치를 표시하는 기호 ‘●’와 현재까지 이동한 계단 수 ◆ 그림 2의 (2) PLAYER는 왼쪽 계단 위에서 COMPUTER는 오른쪽 계단 위에서 게임을 시작한다. PLAYER는 ‘○’, COMPUTER는 ‘●’ 기호로 현재 위치를 나타내고 있다. 현재는 둘 다 이동한 계단수가 (1) (2) 4 0인 상태이다. 게임 도중에 같은 계단에 서게 되면 기호 ‘◑’로 표시하도록 한다. 게임을 위해 이동해야 할 계단의 수는 홀수일 때와 짝수일 때의 구성이 다르니 그림 3과 Appendix의 그림 17을 참고하여 작성하도록 한다. 그림 3의 빨간색으로 표시된 숫자는 플레이어가 이동하게 될 순서이며 플레이어가 현재 위치에서 한 계단을 이동하게 되면, 1이라고 적힌 위치로 이동하게 된다. 플레이어와는 반대로 컴퓨터는 현재 위치에서 한 계단을 이동하게 되면 그림 3의 (a)의 경우 10, 3의 (b)의 경우 11이라고 적힌 위치로 이동하게 된다. 총 계단 수: 11 PLAYER: ○ < 0> COMPUTER: ● < 0> ○ ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨▨▨▨▨▨▨ 계속하려면 엔터를 눌러주세요… (a) 총 계단수가 홀수인 경우 (b) 총 계단수가 짝수인 경우 그림 3. 총 계단 수 예시 화면 ➢ 계단을 출력하기 위해서 다음과 같은 함수를 정의한 후 사용한다. ⚫ print_stairs(): 컴퓨터와 플레이어의 현재 이동한 계단 수와 이동해야 할 총 계단 수를 매개변수를 전달받아 화면에 현재 진행상황을 출력한다. 승부가 결정될 때마다 해당함수를 호출하여 현재 진행상황을 지속적으로 출력한다. (중첩 for문을 사용하여 구현할 것) 그림 3의 상태에서 엔터를 누르면 화면 지우기 후 그림 4와 같이 가위, 바위, 보 중 하나를 선택하는 화면으로 넘어간다. 플레이어는 ‘가위’, ‘바위’, ‘보’ 중 하나를 선택하여 입력한다. 선택 범위를 벗어나는 입력에 대한 실행 예시는 그림 14를 참조하도록 한다. 컴퓨터는 random 모듈의 함수를 사용하여 ‘가위’, ‘바위’, ‘보’ 중 하나의 후보를 선택하게 된다. (단, 컴퓨터는 프로그램을 실행할 때마다 랜덤하게 가위바위보를 내도록 구현해야 한다.) ➢ 컴퓨터의 선택을 생성하기 위해서 다음과 같은 함수를 정의한 후 사용한다. ⚫ computer_choice(): ‘가위’, ‘바위’, ‘보’ 중 무작위로 하나의 후보 선택 후 return 플레이어의 선택 후 그림 4와 같이 플레이어와 컴퓨터가 각각 무엇을 냈는지 출력해 준다. 그림 4는 컴퓨터가 바위, 플레이어가 보를 선택한 후 출력한 예시, 그림 5는 컴퓨터와 플레이어 모두 가위를 선택한 후 출력한 예시이다. 총 계단 수: 12 PLAYER: ○ < 0> COMPUTER: ● < 0> ○ ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨ 계속하려면 엔터를 눌러주세요… 11 1 10 2 9 3 8 4 7 5 6 12 1 11 2 10 3 9 4 8 5 7 6 5 [공격권 결정 가위바위보] 가위, 바위, 보 중 하나 선택: 보 [컴퓨터 선택] ┌──────────────────┐ │ │ │ ▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩ │ │ │ └──────────────────┘ [플레이어 선택] ┌──────────────────┐ │ │ │ ▩▩▩▩▩ │ │ ▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩ │ │ │ └──────────────────┘ [결과] 플레이어 공격, 컴퓨터 수비입니다. 계속하려면 엔터를 눌러주세요… 그림 4. 공격권 결정을 위한 가위바위보 – 플레이어 승리 예시 ➢ 가위바위보 출력을 위해 아래의 함수를 정의하고 사용한다. ⚫ print_scissors() 그림 5의 [컴퓨터 선택] 출력과 같이 가위 이미지를 출력 ⚫ print_rock() 그림 4의 [컴퓨터 선택] 출력과 같이 바위 이미지를 출력 ⚫ print_paper() 그림 4의 [플레이어 선택]의 출력과 같이 보 이미지를 출력 그림 4와 같이 가위바위보에서 승부가 가려진 경우 “[결과] 플레이어 공격, 컴퓨터 수비입니다.” 혹은 “[결과] 컴퓨터 공격, 플레이어 수비입니다.” 를 출력하고 엔터 입력을 기다린다. 만약 ‘공격권 결정 가위바위보’에서 승부가 가려지지 못한 경우 그림 5와 같이 “[결과] 무승부입니다.” 를 출력한 후 엔터 입력을 기다린다. 엔터 입력이 들어온 경우 화면을 지우고 위의 과정을 승부가 결정될 때까지 반복한다. 6 [공격권 결정 가위바위보] 가위, 바위, 보 중 하나 선택:Scissors [Computer Selection] ┌──────────────────┐ │ ▩▩ │ │ ▩▩ ▩▩▩▩▩ │ │ ▩▩▩▩▩ ▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩ ▩▩▩▩▩ │ │ ▩▩▩▩▩▩ ▩▩▩▩▩ │ │ ▩▩▩ ▩▩▩ │ └──────────────────┘ [Player Selection] ┌───────────────────┐ │ ▩▩ │ │ ▩▩ ▩▩▩▩▩ │ │ ▩▩▩▩▩ ▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ ▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩ ▩▩▩▩▩ │ │ ▩▩▩ ▩▩ │ └──────────────────┘ [Result] Tie. Press Enter to continue… Figure 5. Rock-paper-scissors to determine attack right – Example of a draw If the Enter input is entered while the attack and defense are determined as in Figure 4, the screen is cleared and the Rock-paper-scissors input is received again as in Figure 6. At this time, the number of spaces moved in case of victory is displayed at the top of the screen. The number of spaces moved in case of victory starts with 1 and increases by 1 for each time the game is tied. [Mukjjippa] Number of spaces moved in case of victory: 1 Player attacks, computer defends. Choose one of rock, paper, scissors: Figure 6. Waiting for screen input after attack/defense is determined The computer uses the computer_choice() function mentioned above to randomly select one of rock, paper, scissors. If the winner is not decided after the player’s selection, the winner according to the Mukjjipa rules takes the right to attack and the above process is repeated until a winner is decided. Figure 7 is an example of the output when the computer takes the right to attack after the player fails to attack while having the right to attack. “Computer attacks, player defends.” is printed at the bottom. 7 [Mukjjipa] Number of spaces to move when winning: 1 Player attacks, computer defends. Choose one of rock, paper, scissors: Paper [Computer choice] ┌──────────────────┐ │ ▩▩ │ │ ▩▩ ▩▩▩▩▩ │ │ ▩▩▩▩▩ ▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩ ▩▩▩▩▩ │ │ ▩▩▩▩▩▩ ▩▩▩▩▩ │ │ ▩▩▩ ▩▩▩ │ └──────────────────┘ [Player Selection] ┌───────────────────┐ │ │ │ ▩▩▩▩▩ │ │ ▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ └──────────────────┘ [Result] Computer attacks, player defends. Press Enter to continue… Figure 7. Example of a computer attack after a player’s attack fails If the winner is not determined, repeat the above process until the winner is determined, but increase the ‘number of spaces to move when winning’ by 1 each turn. Figure 8 is an example of the state after pressing Enter in Figure 7, and the screen is cleared and the ‘number of spaces to move when winning’ is waited for again. Unlike Figure 7, you can see that the ‘number of spaces to move when winning’ has increased from 1 to 2, confirming that the computer has the right to attack. [Mukjjippa] Number of spaces to move when winning: 2 Computer attacks, player defends. Choose one of rock, paper, scissors: Figure 8. After pressing Enter in the state of Figure 7, wait for screen input When the computer and player have made the same choice and the winner is determined, as in Figure 9, Mukjjippa ends. Figure 9 is an example of the state when the player has the right to attack and both the player and the computer select ‘paper’, and the winner is determined in 5 turns, allowing the player to move 5 spaces. 8 [Mukjjippa] Number of spaces moved when winning: 5 Player attacks, computer defends. Choose one of rock, paper, or scissors: Paper [Computer choice] ┌───────────────────┐ │ │ │ ▩▩▩▩▩ │ │ ▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩ │ │ │ └───────────────────┘ [Player Selection] ┌───────────────────┐ │ │ │ ▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩ │ │ │ └──────────────────┘ [Result] Mukjjippa ends Player wins, moves 5 spaces. Press Enter to continue… Figure 9. Example when the game is decided by player victory If the player presses Enter in a state where the game is decided as in Figure 9, the screen is cleared and the next game proceeds immediately. At this time, the current positions of the player and the computer on the stairs are displayed in numbers and pictures as in Figure 10. Since the game was decided in 5 turns, you can see that the player moved 5 spaces by applying the previously stated staircase movement rules. Total number of stairs: 12 PLAYER: ○ < 5> COMPUTER:● < 0> ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨○ ▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨ Press Enter to continue… Figure 10. Example 9 when the player moves 5 spaces after winning in the state of Figure 2 as in Figure 9 Figures 11 and 12 are examples of cases where the computer wins in 4 turns following the state of Figure 10. When the player’s position movement is 5 and the computer’s position movement is 0, the computer wins in 4 turns and moves 4 steps. The result of the game is displayed as “Computer wins, moves 4 steps” as in Figure 11. When the player presses Enter, the screen is cleared and the result of the game is displayed as in the example in Figure 12. [Mukjjippa] Number of steps moved in case of victory: 4 Computer attacks, player defends. Choose one of rock, paper, scissors: Scissors [Computer Choice] ┌──────────────────┐ │ ▩▩ │ │ ▩▩ ▩▩▩▩▩ │ │ ▩▩▩▩▩ ▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩ ▩▩▩▩▩ │ │ ▩▩▩▩▩▩ ▩▩▩▩▩ │ │ ▩▩▩ ▩▩▩ │ └──────────────────┘ [Player Selection] ┌───────────────────┐ │ ▩▩ │ │ ▩▩ ▩▩▩▩▩ │ │ ▩▩▩▩▩ ▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ ▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩ ▩▩▩▩▩ │ │ ▩▩▩ ▩▩ │ └─────────────────┘ [Result] Computer wins after Mukjjippa ends, moves 4 spaces. Press Enter to continue… Figure 11. Example when the game is decided by a computer victory Total number of steps: 12 PLAYER: ○ < 5> COMPUTER: ● < 4> ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨ ●▨▨▨▨ ▨▨▨▨▨○ ▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨ Press Enter to continue… Figure 12. Example when the game is decided by a computer victory and moves 4 steps 10 Figure 13 shows a case where the player and the computer stand on the same step position in the middle of the game, and the position is indicated by the symbol ‘◑’. Total number of steps: 12 PLAYER: ○ < 3> COMPUTER: ● < 9> ▨ ▨ ▨▨ ▨▨ ▨▨ ▨▨▨◑ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨ Press Enter to continue… Figure 13. If the player and computer are in the same position during the game, if the player selects and inputs a candidate that is out of the rock, paper, scissors game, the player is prompted to input again until a normal input is received, as in Figure 14, without any special error message. [Rock-paper-scissors to decide the right to attack] Choose one of rock, paper, scissors: Muk Choose one of rock, paper, scissors: Pa Choose one of rock, paper, scissors: Scissors [Computer choice] ┌───────────────────┐ │ │ │ ▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ └──────────────────┘ [Player Selection] ┌───────────────────┐ │ ▩▩ │ │ ▩▩ ▩▩▩▩▩ │ │ ▩▩▩▩▩ ▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩▩▩ ▩▩▩▩▩▩ │ │ ▩▩▩▩▩▩▩ ▩▩▩▩▩ │ │ ▩▩▩ ▩▩ │ └──────────────────┘ [Result] Computer attacks, player defends. Press Enter to continue… Figure 14. Example of incorrect input by player 11 II. Game End The game ends when either the computer or the player reaches the opponent’s starting point. The example on the left of Figure 15 is an example of a state where both the player and the computer are on the 11th step out of 12 stairs. In the state on the left of Figure 15, the player won in 2 turns and moved 2 steps. The player needs to move 2 steps from the 11th step, but since there are a total of 12 stairs, the player’s final position is the 12th step, which is the computer’s game starting position. Then, as in the example on the right of Figure 15 below, “Player final victory!!!” is printed and the game ends. Total number of steps: 12 PLAYER: ○ <11> COMPUTER: ● <11> ▨● ○▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨ Press Enter to continue… Figure 15. Example of game end (Player wins) (Edit player’s final victory position) Figure 16 shows the case where the computer reaches the player’s starting position first, and the program ends after printing “Computer final victory!!!” Total number of steps: 12 PLAYER: ○ <8> COMPUTER: ● <12> ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ○▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨▨▨▨▨▨▨▨▨▨▨▨▨ COMPUTER FINAL WIN!!! ▨▨▨▨▨▨▨▨▨▨▨▨▨▨ End the game… Figure 16. Example of game end (computer wins) Total number of steps: 12 PLAYER: ○ <12> COMPUTER: ● <11> ○ ▨● ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨▨▨▨▨▨▨▨▨ Player’s final victory!!! ▨▨▨▨▨▨▨▨▨▨▨▨▨ Exit the game… 12 Tips ◼ Clearing the screen In this assignment, you will often need to use clearing the screen. However, the clearing screen command to use may vary depending on the environment due to differences in development environment and execution such as jupyter notebook, Windows/Linux, etc. In this assignment, you will create and use the clear_screen() function to clear the screen as shown below. Failure to follow this will result in a penalty. In the Windows/Linux environment, you can use the os module to clear the current console window. In the jupyter notebook environment, you can use the IPython module to clear the current output. Create the code below according to your environment and run it, then comment out the clear_screen() function part and run it to understand the difference. import os from IPython.display import clear_output def clear_screen(): # os.system(‘cls’) # Uncomment when running in a Windows console window # os.system(‘clear’) # Uncomment when running in a Linux console window clear_output() # Comment out when running outside of jupyter notebook return print(‘Hello, World!’) clear_screen() # Comment out the relevant part and run to compare the results print(‘Hello, World!’) 13 Appendix ◼ Example of the number of stairs Total number of stairs: 13 PLAYER: ○ < 0> COMPUTER: ● < 0> ○ ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨▨▨▨▨ Press Enter to continue… Total Steps: 14 PLAYER: ○ < 0> COMPUTER: ● < 0> ○ ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨ Press Enter to continue… (a) If the total number of steps is 13 (b) If the total number of steps is 14 Total number of steps: 15 PLAYER: ○ < 0> COMPUTER: ● < 0> ○ ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨▨▨ ▨▨▨▨▨▨▨▨▨ Press Enter to continue… Total Steps: 16 PLAYER: ○ < 0> COMPUTER: ● < 0> ○ ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨▨ ▨▨▨▨▨▨▨▨ ▨▨▨▨▨▨▨▨▨▨ Press Enter to continue… (c) When the total number of steps is 13 (d) When the total number of steps is 14 Figure 17. Example screen of total number of steps Figure 17 is an example of how the staircase output changes as the number of steps increases. You can see that it has a V-shape, with the middle section being the lowest and the layers getting higher as you go towards the edges.○ < 0> COMPUTER: ● < 0> ○ ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨▨ ▨▨▨▨▨▨▨ ▨▨▨▨▨▨▨▨ ▨▨▨▨▨▨▨▨▨ Press Enter to continue… (c) When the total number of steps is 13 (d) When the total number of steps is 14 Figure 17. Example screen of total number of steps Figure 17 is an example of how the staircase output changes as the number of steps increases. You can see that the middle space is the lowest and the floors get higher as you go towards the edge, forming a V-shape.○ < 0> COMPUTER: ● < 0> ○ ● ▨ ▨ ▨▨ ▨▨ ▨▨▨ ▨▨▨ ▨▨▨▨ ▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨ ▨▨▨▨▨▨▨ ▨▨▨▨▨▨▨ ▨▨▨▨▨▨▨▨ ▨▨▨▨▨▨▨▨▨ Press Enter to continue… (c) When the total number of steps is 13 (d) When the total number of steps is 14 Figure 17. Example screen of total number of steps Figure 17 is an example of how the staircase output changes as the number of steps increases. You can see that the middle space is the lowest and the floors get higher as you go towards the edge, forming a V-shape.