top of page

Prompt Engineering for Coding - 4 Examples of Prompts from the Previous Framework

Here's quick Summary of Framework:

1. The prompt engineering tutorials on Youtube and Twitter giving you a “killer prompt” asking ChatGPT working step by step and asking clarifying questions etc, yes that works, and still must be used, but its much more complex than that for complex tasks.

2. Give ChatGPT its role, reminding it of its role every now and then.

3. Break the code into different sections.

4. For every step forward, remind ChatGPT of the newest versions of the code, section by section, everytime something new implemented works.

5. For every single iteration, update, change and addition to the code that ChatGPT writes for you, run it. Test it, debug it then confirm the change with chatGPT by doing (4).

6. Confirm with ChatGPT your process for working. E.g. for each specific task: brainstorming of task, confirmation of task, further clarification and analysis of task, ChatGPT writing the code, explaining the code, you testing the code, debugging the code, successfully running the code and reminding chatGPT of the latest iteration section by section of the code.

7. Remind (copy and paste) your framework and process of working (step 6) to ChatGPT again.


Example prompt for (2) – Giving GPT its role:

Me:

“That sounds good. Before we proceed, I'll give you the following. You are my game engineer, and responsible for writing the code for this power up toin coss game. Since you have limitations in the amout of code you can give me, you must think step by step. Therefore you must break the project up into easily digestible code and give me that code section by section. Ultimately you must give me complete code, section by section and then once i combine the code, ensure this works. Lastly for each section you give me, check thoroughly first that it works before giving it to me because i am not a coder and would not know how to debug your code. Thanks”

ChatGPT:

Understood. I'll provide you with the code step by step, ensuring that each section works before moving on to the next part. I'll also give you an explanation of each section to help you understand how the code works and how to piece it together. Let's start with the first part: modifying the existing game code to include power-up selection at the beginning of the game. Here's the updated code for Part 1: (code)


Example Prompts for (3 and 4) – Breaking task into sections, reminding and updating GPT on the sections:

Me:

ok. Everything works. Let me send you all the sections of the code, and you take a snap shot of it. As all the code here works. I'll separate it into 3 messages. 1.) The set up, defining get_player_choice, defining select_power_ups(player_name), defining calculate_points 2.) The main loop 3.) The winner, points = calculate_points section ok?

ChatGPT:

Sure, that sounds good. Please go ahead and send the three sections of the code, and I'll take a snapshot of the complete working code for you.

Me:

Here's the setup, remember it: (I paste code for section 1.

ChatGPT:

Thank you for sending the first section of the code. I've noted down the setup, including the imports, the get_player_choice function, select_power_ups function, and calculate_points function.

Me:

Here's the first part of while loop right before the winner, points = calculate points section, rememebr it: (I paste the code for section 2)

ChatGPT:

Thank you for sending the second section of the code. I've noted down the first part of the while loop, which includes the conditions for using the 'Double Points' power-up for both players, the coin toss result, and the assignment of the active power-ups for each player.

Me:

here's the last section, remember it: (I paste section 3)

ChatGPT

Thank you for sending the last section of the code. I've noted down the part that calculates the winner and updates the points for each round. This section also includes the logic for displaying the updated points after each round and declaring the final winner at the end of the game. I will remember this code as requested.

Me:

That's it. So from now on we shall call these sections 1, 2 and 3. Now, lets move on to the next power up. That's reverse coin. For your memory, this is the code you gave me: if player1_active_power_up == "Reverse Coin": player2_choice = "Heads" if player2_choice == "Tails" else "Tails" if player2_active_power_up == "Reverse Coin": player1_choice = "Heads" if player1_choice == "Tails" else "Tails" and that's it and you said put it in the main while game loop. Seems awfully simple. I don't think thats the case. Before we do it lets check everything. Let me clarify reverse coin rules: 1. If a player uses the "Reverse Coin" power up, their opponent's choice will be reversed (Heads will become Tails and vice versa). 2. If both players use the "Reverse Coin" power up in the same round, their choices will still be reversed, effectively canceling each other out. 3. Players will be notified of the reversal after the round is over. 4. Can only be used once, so don't ask again once its consumed. 5. If the player doesnt choose this as their power up, also they should not ask the player whether or not to use it as it was never chosen in the first place.


Example prompt and situation for (5) – Fixing / Updating Code Example:

Me:

sorry there was a connection lost so i took a nap. Good day, let me repeat the last message: Ok. you are confused again. Once more I'll update you with the most updated 3 sections of the code, and then you tell me what needs to be changed so that Once swap points is used, it is consumed and moreover, if both players use swap points, the effect is cancelled so nothing happens, however, also the swap points is consumed and cant be used again. Okay? I'll post section1 in next message. I have found i get the best results when i update your database. And our objective is to improve the swap power up because we encountered a minor problem which let me show you: Your code is working fine, when both players use the swap power up, their points are not swapped. Your code is working perfectly fine. The only problem with your code is that when both players use swap: 1.) Nothing should happen (you have coded correctly here). 2.) That the power up should be consumed. It was not consumed, that is the problem. It should not be able to be used again.

ChatGPT:

I understand the issue now. Please provide the updated sections of the code, and I'll help you make the necessary changes to ensure the 'Swap Points' power-up is consumed correctly, even when both players use it at the same time.

Me:

cheers. Section 1: (paste code)

ChatGPT:

Thank you for providing Section 1 of your code. Please provide Section 2 and Section 3 as well. This way, I can review the complete code and suggest the required changes to fix the 'Swap Points' power-up consumption issue.

Me:

Section 2: (paste code)

ChatGPT:

Thank you for providing Section 2 of the code. Please provide Section 3 as well so I can review the entire code and suggest the required changes to fix the 'Swap Points' power-up consumption issue.

Me:

Section 3: (paste coode)

ChatGPT:

I see the issue now. To fix the 'Swap Points' power-up consumption issue, you need to keep track of whether the 'Swap Points' power-up has been used by the players or not. You can do this by adding two new variables to keep track of their usage and update the ask_power_up_use function calls accordingly. Here's the modified code for Sections 1, 2, and 3: Section 1: Add the following lines at the end of Section 1:

Section 2: Replace the lines with ask_power_up_use for 'Swap Points' with the following code:

Section 3: No changes are needed in Section 3. With these changes, the 'Swap Points' power-up should be consumed once used, and it will not be available for future rounds.

Me:

You sure? that seems quite a lot of change to just make sure the power up is consumed. please double check that it's not going to affect other sections of the game and the logic

ChatGPT:

I apologize for any confusion. I understand your concern. I have reviewed the code changes, and they should not affect other sections of the game or its logic. The changes made are simply to track the usage of the 'Swap Points' power-up and ensure it is only used once by each player. This is done similarly to how the other power-ups are tracked and consumed. Here's a summary of the changes:

1. In Section 1, we added two new boolean variables to track whether the players have the 'Swap Points' power-up and if they have already used it. This is consistent with how other power-ups are handled. 2. In Section 2, we updated the 'ask_power_up_use' function calls for the 'Swap Points' power-up. The new code checks if the player has the 'Swap Points' power-up and if they have not used it before. If both conditions are met, the player is prompted to use the power-up, and the power-up is marked as used.

The modifications ensure that the 'Swap Points' power-up is only consumed once and do not affect other parts of the game. Please let me know if you have any further questions or concerns.


Example for (6) – Referral to Process (We developed a 6 step system and we keep referring back to it):

ChatGPT:

I have double-checked the code, and everything appears to be in order. The basic game structure and main game loop handle player inputs and points correctly, and the power-up selection and activation prompts are working as intended. We can now proceed with implementing the logic for the power-ups.

Me:

Ok. Like before lets implement that like this. We will code each power up separately. For each power up you will: 1. Clarify me the logic and any loopholes. 2. Code and explain to me each line. 3. Tell me where to put that code back into the original code 4. tell me any code to remove. 5. check and confirm 6. next power up and repeat process for all 5 power ups. Cool?

ChatGPT:

Sure, we can follow the steps you've outlined for each power-up. To make it easier, I'll list the power-ups again for reference:

We refer to it again and again during the process of coding ->

ChatGPT:

Sure, let's move on to the second power up, which is the "Reverse Coin" power up. Let me first clarify the logic and check if there are any loopholes:

  1. If a player uses the "Reverse Coin" power up, their opponent's choice will be reversed (Heads will become Tails and vice versa).

  2. If both players use the "Reverse Coin" power up in the same round, their choices will still be reversed, effectively canceling each other out.

  3. Players will be notified of the reversal after the round is over.

Now, let's implement the "Reverse Coin" power up following the 6 steps:

  1. We have already clarified the logic.

  2. I will provide the code snippet and explain each line.

  3. I will tell you where to insert the code in the main game loop.

  4. I will tell you which lines of code, if any, need to be removed.

  5. I will check and confirm.

  6. We will then move on to the next power-up.

Here's the code snippet for the "Reverse Coin" power up: code

Me:

This is great. Lets continue working in this 6 step process. Next power up thanks. I think its peek coin

ChatGPT:

Yes, the next power up is "Peek Coin". Let's follow the 6-step process again:

1. We have already clarified the logic for "Peek Coin":

  • If a player uses the "Peek Coin" power up, they will know the outcome of the coin toss before making their choice for that round.

  • If both players use the "Peek Coin" power up in the same round, both players will know the outcome of the coin toss before making their choices.

2. Here's the code snippet for the "Peek Coin" power up: code

Explanation:

  • The first line checks if either player has activated the "Peek Coin" power up.

  • The next line generates a random coin toss result for the players to peek at.

  • The following two lines display the peeked coin toss result to each player who activated the "Peek Coin" power up.

  • The last line sets the toss result to the peeked result if either player used the power up.

  • If neither player used the "Peek Coin" power up, the toss result is generated randomly as usual.

3. To integrate this code into the main game loop, you should replace the existing line that calculates the toss result (toss_result = random.choice(["Heads", "Tails"])) with the entire code snippet provided above. 4. You will need to remove the existing line that calculates the toss result (toss_result = random.choice(["Heads", "Tails"])) because it's replaced by the code snippet for the "Peek Coin" power up. 5. I've checked the code, and it should work as expected. 6. Once you've added this, we can move on to the next power-up.


Me:

ok, lets go through the 6 steps for the nextt power up. we need to discuss this one as it hasnt been discussed before

ChatGPT:

Sure, let's move on to the "Swap Points" power up. This power up allows a player to swap their points with their opponent's points.

  1. Clarify the logic and any loopholes:

  • When a player uses the "Swap Points" power up, their points will be exchanged with their opponent's points.

  • This power up can be strategically used when a player is losing and wants to turn the game around.

Please let me know if there's anything you'd like to clarify or change about this power up before we proceed with the coding steps.

Me:

well obviously it cant be used when the winner has been determined right? like it cant be used when a player has reached 10 points?

ChatGPT:

You're correct. The "Swap Points" power up should not be allowed to be used once a player has reached 10 points and been declared the winner. The power up can only be used during the game, before either player reaches the winning score. I will keep this in mind while implementing the code for this power up.

Me:

how about this can only be implemented when the opposite player has equal to or less than 5 points? above that, then this power up cannot be used? also, this power up of course can only be used once. is this hard to code?

ChatGPT:

Implementing these restrictions on the "Swap Points" power up is not too difficult. We can add conditions to check if the opponent has 5 points or fewer and if the power up has not been used before. If both conditions are met, the player can use the power up. I'll keep this in mind while writing the code for this power up.

Me:

Ok. Lets do it. 6 step process please.

ChatGPT:

Step 1: Clarify the logic and any loopholes

  • The "Swap Points" power-up can be used only once.

  • It can only be used if the opponent has 5 points or fewer.

  • Upon activation, the players' points are swapped.

Step 2: Code for the "Swap Points" power-up: Step 3: Tell me where to put that code back into the original code Place the above function at the beginning of the code, along with the other function definitions. Step 4: Tell me any code to remove No code needs to be removed for this step. Step 5: Check and confirm Now, call the swap_points function inside the main game loop, right after activating power-ups and before determining the winner of the round: Step 6: Next power-up and repeat the process for all 5 power-ups We have now implemented the "Swap Points" power-up. We will move on to the next power-up following the same 6 step process.



Comentarios


bottom of page