Question
Project 1: Tic-Tac-Toe
“Here’s my idea: I want to build a tic-tac-toe game. The user creates an account if they don’t already have one and are taken to the main game board. From there the player will play against the computer in either easy, intermediate, or advanced mode, so I will need to write the code for the computer player. When the game is over their lifetime win total is updated. I will also keep track of how long the game took.”
Step 1. Choose two Datasets: Open a project on Code Studio and look through the different datasets available. Choose two that look interesting to you.
Dataset Name: _____________________________________________.
What column(s) of data will you use in your app?
Dataset Name: _____________________________________________.
What column(s) of data will you use in your app?
Step 2. Brainstorm an App: Consider the columns of data that you are using.
How will your app traverse this data?
Your app will use (circle): MAP REDUCE FILTER
Filter (most common option): use the list from one column to determine information that will be filtered from a list created by another column
Example: dogHeight filters dogNames, so only the names of small dogs are added to the filtered list
Map: Add or change each item in a list
Example: map a list of numbers pulled from a column using Math.round - now each number is rounded
Reduce: Reduce the data in a list to a single number
Example: find the smallest number in a list
Step 3: Traverse the app. Explain how you will traverse the app in more detail (give concrete examples of how you might do this):
How will you use the data?
If filtering, how will you filter the data?
If mapping, how will you map the data?
If reducing, how will you reduce the data?
“Here’s my idea: I want to build a tic-tac-toe game. The user creates an account if they don’t already have one and are taken to the main game board. From there the player will play against the computer in either easy, intermediate, or advanced mode, so I will need to write the code for the computer player. When the game is over their lifetime win total is updated. I will also keep track of how long the game took.”
Step 1. Choose two Datasets: Open a project on Code Studio and look through the different datasets available. Choose two that look interesting to you.
Dataset Name: _____________________________________________.
What column(s) of data will you use in your app?
Dataset Name: _____________________________________________.
What column(s) of data will you use in your app?
Step 2. Brainstorm an App: Consider the columns of data that you are using.
How will your app traverse this data?
Your app will use (circle): MAP REDUCE FILTER
Filter (most common option): use the list from one column to determine information that will be filtered from a list created by another column
Example: dogHeight filters dogNames, so only the names of small dogs are added to the filtered list
Map: Add or change each item in a list
Example: map a list of numbers pulled from a column using Math.round - now each number is rounded
Reduce: Reduce the data in a list to a single number
Example: find the smallest number in a list
Step 3: Traverse the app. Explain how you will traverse the app in more detail (give concrete examples of how you might do this):
How will you use the data?
If filtering, how will you filter the data?
If mapping, how will you map the data?
If reducing, how will you reduce the data?
Answers
GPT-4o mini
### Step 1: Choose two Datasets
#### Dataset Name: **Game Outcome Statistics**
**What column(s) of data will you use in your app?**
- `Player1Wins`
- `Player2Wins`
- `GameDuration`
These columns will help track the outcomes of the games played and how long each game took, which can be used to analyze user performance over time and update win totals.
#### Dataset Name: **User Accounts**
**What column(s) of data will you use in your app?**
- `Username`
- `LifetimeWins`
- `AccountCreationDate`
These columns will allow for user account management, enabling authentication and tracking historical win data, which will be updated post-game.
---
### Step 2: Brainstorm an App
**How will your app traverse this data?**
Your app will primarily use a combination of **FILTER** and **MAP**.
- **Filter**: We will filter to check for an existing username in the `User Accounts` dataset to prevent duplicate account creation, and to filter games played by a specific user in the `Game Outcome Statistics` dataset.
- **Map**: We will map the `GameDuration` column to convert the game duration from seconds to a human-readable format (e.g., minutes and seconds) for display purposes.
---
### Step 3: Traverse the app
**How will you use the data?**
1. **If filtering, how will you filter the data?**
- **Account Creation**: Check if the entered username exists in the `User Accounts` dataset.
- For example: `existingUsernames.filter(user => user.Username === enteredUsername)`.
- **Game Records**: When retrieving game outcomes for a specific user, filter the `Game Outcome Statistics` dataset to display only games played by the current user.
- E.g., `gameStats.filter(game => game.Player1 === currentUser.Username || game.Player2 === currentUser.Username)`.
2. **If mapping, how will you map the data?**
- Convert the `GameDuration` data to a more readable format (i.e., from seconds to minutes:seconds).
- For example:
```javascript
const formattedDurations = gameStats.map(game => {
const minutes = Math.floor(game.GameDuration / 60);
const seconds = game.GameDuration % 60;
return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
});
```
3. **If reducing, how will you reduce the data?**
- To update the lifetime wins, we need to reduce the `Player1Wins` and `Player2Wins` columns when calculating the total wins for each user.
- For example:
```javascript
const totalWins = games.reduce((acc, game) => {
if (game.Player1 === currentUser.Username) {
return acc + game.Player1Wins;
} else if (game.Player2 === currentUser.Username) {
return acc + game.Player2Wins;
}
return acc;
}, 0);
```
By following this structure, you can effectively manage user accounts, track game outcomes, and provide meaningful feedback to players in your Tic-Tac-Toe game.
#### Dataset Name: **Game Outcome Statistics**
**What column(s) of data will you use in your app?**
- `Player1Wins`
- `Player2Wins`
- `GameDuration`
These columns will help track the outcomes of the games played and how long each game took, which can be used to analyze user performance over time and update win totals.
#### Dataset Name: **User Accounts**
**What column(s) of data will you use in your app?**
- `Username`
- `LifetimeWins`
- `AccountCreationDate`
These columns will allow for user account management, enabling authentication and tracking historical win data, which will be updated post-game.
---
### Step 2: Brainstorm an App
**How will your app traverse this data?**
Your app will primarily use a combination of **FILTER** and **MAP**.
- **Filter**: We will filter to check for an existing username in the `User Accounts` dataset to prevent duplicate account creation, and to filter games played by a specific user in the `Game Outcome Statistics` dataset.
- **Map**: We will map the `GameDuration` column to convert the game duration from seconds to a human-readable format (e.g., minutes and seconds) for display purposes.
---
### Step 3: Traverse the app
**How will you use the data?**
1. **If filtering, how will you filter the data?**
- **Account Creation**: Check if the entered username exists in the `User Accounts` dataset.
- For example: `existingUsernames.filter(user => user.Username === enteredUsername)`.
- **Game Records**: When retrieving game outcomes for a specific user, filter the `Game Outcome Statistics` dataset to display only games played by the current user.
- E.g., `gameStats.filter(game => game.Player1 === currentUser.Username || game.Player2 === currentUser.Username)`.
2. **If mapping, how will you map the data?**
- Convert the `GameDuration` data to a more readable format (i.e., from seconds to minutes:seconds).
- For example:
```javascript
const formattedDurations = gameStats.map(game => {
const minutes = Math.floor(game.GameDuration / 60);
const seconds = game.GameDuration % 60;
return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
});
```
3. **If reducing, how will you reduce the data?**
- To update the lifetime wins, we need to reduce the `Player1Wins` and `Player2Wins` columns when calculating the total wins for each user.
- For example:
```javascript
const totalWins = games.reduce((acc, game) => {
if (game.Player1 === currentUser.Username) {
return acc + game.Player1Wins;
} else if (game.Player2 === currentUser.Username) {
return acc + game.Player2Wins;
}
return acc;
}, 0);
```
By following this structure, you can effectively manage user accounts, track game outcomes, and provide meaningful feedback to players in your Tic-Tac-Toe game.