Skip to content

Commit

Permalink
Merge branch 'main' of github.com:CMU-17-214/f2023 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ckaestne committed Oct 30, 2023
2 parents 5eb0d7a + 2265f16 commit 47b94af
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 15 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ The schedule below reflects our current plans, but will be updated throughout th
</tr>
<tr class="">
<td>Tue, Oct 3</td>
<td>Introduction to GUIs and Concurrency</td>
<td><a href="https://docs.google.com/presentation/d/1UwOwQaCNsmRiubei6jqkrwX5IA_fWaHL4TYgnFXFCvE/edit?usp=sharing">Introduction to GUIs and Concurrency</a></td>
<td><a href="https://cmu.primo.exlibrisgroup.com/permalink/01CMU_INST/1feg4j8/alma991019576375404436">Design Patterns Explained</a> or <a href="https://refactoring.guru/design-patterns/catalog">Refactoring Guru</a> on Observer and Decorator</td>
</tr>
<tr>
Expand All @@ -172,16 +172,16 @@ The schedule below reflects our current plans, but will be updated throughout th
</tr>
<tr>
<td>Tue, Oct 10</td>
<td>(Towards) Web Apps</td>
<td><a href="https://docs.google.com/presentation/d/1MYznh142GLDOjTiruuP475bD-EpPpYcJbYXLWJJ7KHU/edit?usp=sharing">Asynchrony in JavaScript</a></td>
<td></td>
</tr>
<tr>
<td>Wed, Oct 11</td>
<td><span class="rec">Lab 7</span> GUI intro </br>
<td><span class="rec">Lab 7</span> <a href="https://github.com/CMU-17-214/f2023/blob/main/labs/lab07.md">GUI intro </a></td>
</tr>
<tr>
<td>Thu, Oct 12</td>
<td>Concurrency: Safety and Immutability</td>
<td><a href="https://docs.google.com/presentation/d/1fOKIktVlnDzdCzNcOj-QLD8wqodA4d_fhzhixFXPzKg/edit?usp=sharing">Concurrency and Hazards</a></td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop">Concurrency model and the event loop</a> + <a href="https://blog.sessionstack.com/how-javascript-works-event-loop-and-the-rise-of-async-programming-5-ways-to-better-coding-with-2f077c4438b5">How JavaScript works</a></td>
</tr>
</tbody>
Expand All @@ -204,22 +204,22 @@ The schedule below reflects our current plans, but will be updated throughout th
</tbody>
<tbody>
<tr>
<td>Mon, Oct 23</td>
<td>Tue, Oct 24</td>
<td><span class="assignment"><span class="hw">HW 4 due</span> <a href="https://github.com/CMU-17-214/f2023/blob/main/assignments/hw4.md">Refactoring</a></td>
<td></td>
</tr>
<tr>
<td>Tue, Oct 24</td>
<td>Concurrency: Patterns and Promises</td>
<td><a href="https://docs.google.com/presentation/d/1RVh8ayQszjt0hHV2Cq8TJglEVkrS1TWKIn0gs9F3XvI/edit?usp=sharing">Concurrency: Reactive Programming</a></td>
<td></td>
</tr>
<tr>
<td>Wed, Oct 25</td>
<td><span class="rec">Lab 8</span> Concurrency & Promises</td>
<td><span class="rec">Lab 8</span> <a href="https://github.com/CMU-17-214/f2023/blob/main/labs/lab08.md">Concurrency & Promises</a></td>
<td></td>
</tr>
<td>Thu, Oct 26</td>
<td>Events everywhere</td>
<td><a href="https://docs.google.com/presentation/d/1tTkDT6dkDBFilVm9M_hYsde6FKx_mfKOs9d4yJNnmJU/edit?usp=sharing">Distributed Systems -- Events everywhere</a></td>
<td></td>
</tr>
</tbody>
Expand All @@ -231,17 +231,17 @@ The schedule below reflects our current plans, but will be updated throughout th
</tr>
<tr>
<td>Tue, Oct 31</td>
<td>Libraries and Frameworks</td>
<td><a href="https://docs.google.com/presentation/d/1wF0pyEZqycWNUnV75QyGTI9bDrtBMIJsnLUVVPLCSTw">Design for Robustness & Distributed Systems</a></td>
<td></td>
</tr>
<tr>
<td>Wed, Nov 1</td>
<td><span class="rec">Lab 9</span> Frameworks</td>
<td><span class="rec">Lab 9</span> <a href="https://github.com/CMU-17-214/f2023/blob/main/labs/lab09.md">ReactJS</a></td>
<td></td>
</tr>
<tr>
<td>Thu, Nov 2</td>
<td>API Design</td>
<td>Libraries and Frameworks</td>
<td></td>
</tr>
</tbody>
Expand Down Expand Up @@ -270,7 +270,7 @@ The schedule below reflects our current plans, but will be updated throughout th
<tbody>
<tr>
<td>Tue, Nov 14</td>
<td>API Design (continued)</td>
<td>API Design</td>
<td></td>
</tr>
<tr>
Expand All @@ -280,7 +280,7 @@ The schedule below reflects our current plans, but will be updated throughout th
</tr>
<tr>
<td>Thu, Nov 16</td>
<td>Design for Robustness & Distributed Systems</td>
<td>API Design (continued)</td>
<td></td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion assignments/hw3.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Specifically, we expect to grade the homework with the following rubric:
**Initial submission (30 points, milestone 3a)**

1. [ ] 10: The GitHub submission includes a reasonably complete version of all design documents that demonstrate a good-faith attempt at modeling the problem (`domain-model.pdf`, <code>system-sequence-diagram.pdf</code>, <code>contract.pdf</code>, `object-model.pdf`, `build-justification.pdf`, and `state-justification.pdf`)
2. [ ] 10: The design documents are submitted in a zip file to Canvas without obvious identifying information (no name or AndrewID in any of the documents)
2. [ ] 10: The design documents and only design documents are submitted in a zip file to Canvas without obvious identifying information (no name or AndrewID in any of the documents)
3. [ ] 10: The GitHub submission includes reasonably complete code and tests that demonstrate a good-faith attempt at implementing the game.

**Domain analysis (25 points, milestone 3a/c):**
Expand Down
2 changes: 1 addition & 1 deletion assignments/hw4.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ The assignment is worth 110 points. We expect to grade the assignment approximat
- [ ] 56pt: For each of the first 7 design problems (responsibility assignment, code duplication, coupling, cohesion, extensibility, encapsulation, and instanceof; not "SubSubSubSubSubArticles"):
- [ ] 4pt: There is an issue on GitHub that (a) names the design problem in the title, (b) identifies an instance of the problem in the code, and (c) explains *why* this is a problem. The issue's text demonstrates an understanding of the design problem.
- [ ] 4pt: The issue is (a) closed with (b) a description of the fix and (c) a link to the commit(s) that contain the fix so that we can find the fix in the implementation. The change indeed improves the design as described without introducing new obvious design problems.
- [ ] 14pt: For "SubSubSubSubSubArticles": An issue (named "SubSubSubSubSubArticles" or similar) describes why the old implementation was problematic. The issue is closed with a description of how it was improved in a way that demonstrates an understanding of design reasoning and the used design pattern. The fixed implementation better handles articles and subarticles with less code duplication and better implementations for common functionality like `getTopics`, `getSize`, and parent/child relationships.
- [ ] 14pt: For "SubSubSubSubSubArticles": An issue (named "SubSubSubSubSubArticles" or similar) describes why the old implementation was problematic. The issue is closed with a description of how it was improved in a way that demonstrates an understanding of design reasoning and the used design pattern (if any). The fixed implementation better handles articles and subarticles with less code duplication and better implementations for common functionality like `getTopics`, `getSize`, and parent/child relationships.
- [ ] 10pt. The repository contains a partial object model in `sub-articles.pdf` in the root directory of your branch that describes the design fix for the "SubSubSubSubSubArticles" problem. It needs only include the classes involved with your fix. The diagram should be consistent with the actual implementation, use suitable notation, and be at the right level of abstraction.
- [ ] 10pt: The git commits are cohesive and have meaningful descriptions that indicate what fix they are part of. The changes did not introduce severe style or readability issues.

Expand Down
Binary file added labs/images/lab07/component.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added labs/images/lab07/jsonFormat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added labs/images/lab07/proxy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added labs/images/lab07/proxy2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added labs/images/lab07/tictactoe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added labs/images/lab08/lab08_project_select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added labs/images/lab08/lab08_select_billing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions labs/lab07.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Lab 7: TicTacToe Client/Server

## Context
TicTacToe is a two-player game where the players take turns marking the spaces in a three-by-three grid with either X or O. The first player to place three of their marks in a horizontal, vertical, or diagonal row is the winner. More information about the game can be found here. In this recitation, you will work on an implementation of the TicTacToe game.

This version of TicTacToe is meant to help you set up Homework 6b (GUI for santorini). It uses a Java backend using a NanoHttpd server and a TS frontend using React.js. This client/server style architecture is commonly used in developing web applications. However, this is a very big topic, we will only cover the essentials for this lab and Homework 4.

## Deliverables
- [ ] Extend the implementation to show the current player and winner of the game in the “instructions” panel of the game.
- [ ] Extend the implementation of the game to allow users to undo steps.
- [ ] Change the styling of the game with CSS files (e.g., change colors).

## Instructions
Clone the TicTacToe repository from: https://github.com/CMU-17-214/f22-rec07

Refer to the README’s of the projects therein for set up instructions. After you run the program, you will be able to play the game through the GUI as illustrated in the snippet below from the link http://localhost:3000/.

![tictactoe](images/lab07/tictactoe.png)


Today’s recitation is all about learning to read and navigate this type of code. The deliverables require you to implement a few very simple improvements, that won’t take you much time at all once you get the hang of how the code is written and structured. So prioritize reading the code and thinking about the flow of information and control.

Instructions: Right now, the game doesn’t tell the user much; once someone has won, it just stops responding. Let’s add an “instructions” element to the HTML body, with the ID “instructions”. The CSS for this element is already present. The text in this element should indicate whose turn it is, or who has won the game (if applicable). Hint: think about all the places affected by this, in terms of client/view (HTML), and server/controller. How do other elements get updated?

Undo: The “Undo” button currently does nothing at all. Let’s wire it up. Much like in the previous exercise, think about all the places where changes need to be made. This one will also require you to get into the game implementation (the model), where most of the functionality needed to facilitate `undo` (tracking a game’s history) is already present. Note that this is strongly supported by the immutable implementation of the game. Again, follow the control flow from the user clicking to (and within) the backend, and back. Use the “history” to implement undo on the game implementation side.

Styling: Make it pretty! You can either expand on the CSS provided -- maybe move it to its own file(s) -- or bring in themes.


### Hint: Key Files
To work with this TicTacToe font-end and back-end implementation, you mainly need to understand 4 files:
App.tsx: the main component of this React project.
App.css: the CSS style file for the application.
Cell.tsx: the React.js component for rendering a cell of the board. You may also define a new style file for the Cell component.
game.ts: it defines the data structure for the game including the GameState and the Cell. These structures should likely match with the data structures defined in your backend.


### Hint: Connecting the Frontend to the Backend
This program already has the frontend connected to the backend for you. How this works is that within the Java backend, nanohttpd sets up a server that runs at http://localhost:8080/. It also sets up two pages, /newgame for creating a new game and /play to play a certain move. Then within the TS frontend, which React hosts at http://localhost:3000/, which is where you should redirect your page to, whenever you go to the /newage or /play pages, a request is sent to the nanohttpd server with the relevant info. The server then responds to React with a JSON, with the updated cells.





## HTML/CSS Review
HTML is the standard markup language for Web pages. It is very similar to XML. CSS is the language we use to style an HTML document. CSS describes how HTML elements should be displayed and looked like. There are a lot of good online resources for learning HTML and CSS, e.g., HTML Tutorial (https://www.w3schools.com/html/default.asp) and CSS Tutorial (https://www.w3schools.com/css/default.asp). Please read them if you are not familiar with these materials.

## Nanohttpd Review
Nanohttpd is a lightweight Java server that is good for very basic web applications. Because of how small and lightweight it is, it is good for embedding into already existing applications without adding too much size or latency to the project. The backend server of this game is built upon it. To learn more about it, please refer to this Nanohttpd Tutorial (https://www.baeldung.com/nanohttpd).

## React.js Review
React.js is a Javascript framework that can be adjusted to work for TypeScript. It is mainly used to make very interactive and dynamic UIs. It allows you to create a complex UI using smaller, isolated pieces of code called “components”. We will use the most basic part of React.js.

### A Little History, Why React.js
Stage 1, at the very beginning, most resources shared on the internet were static, i.e., engineers can use HTML to define their static web pages. They could simply update the HTML files (at the server backend) to change the content they wanted to share. However, the webpage has limited interactivity and cannot load data dynamically after being rendered by the browser.
Stage 2, browsers now support Javascript. Engineers can now use Javascript to change their webpages on the client side (browser) to, e.g., add animation, and load data dynamically. E.g., you may find a website that will dynamically update the items as you scroll down the page.
Stage 3, most of the websites are still relying on the technique in Stage 2, even React.js. However, some old Javascript frameworks require you to manually load the data and add/delete HTML elements. This is painful and tedious when your webpage is highly interactive and dynamic. Thus, frameworks like React.js are created. You can easily bind your data and code with the HTML element, and the framework will automatically update the view.

### Component
Components are a key element of React.js projects. Each component defines 1) the HTML element about how you want to visualize your data, 2) data bound with this component, e.g., a component is used to render the board, so it should associate with the board data, 3) the code logic for how the data and view will dynamically change or respond to user input. Thus, we can break the web application into small pieces (components), each with its own view definition, data, and implementation.

A very simple component could look like:

![component](images/lab07/component.png)

Each component will have:
props, an object passed from the caller that holds the data of this component, e.g., in the example, we assume that the parent component of Welcome will pass in the name of this Welcome component instance, which the name will be stored in props, so we can access the name using this.props.name;
state, an object managed by the component itself that can also hold the data of the component, we can use setState() function to update its value, and the view will automatically update accordingly;
render(), the function you must implement which defines how the component will be rendered. In React.js, we use JSX (https://legacy.reactjs.org/docs/introducing-jsx.html) to directly define HTML as code in Javascript or Typescript. In the example, we create a tag, and the name is dynamically obtained from the `this.props.name` object. An advantage of React is that, when the value of name is changed, the view will automatically update.

Some notes:
props should not be changed by the component itself but instead will be changed by its parent component. On the other hand, state is usually the internal data of the component which should be managed by the component itself.
constructor(props) is not necessary for a component. The only needed one is the render() function

### Proxy
One thing this lab makes use of is a TypeScript property called proxy. Proxy essentially tells the front end to route all connections to the base url given in the package.json. For this assignment, the proxy routes to http://localhost:8080/, which is the url that the backend server is running on. This means that when we have a command like await fetch(“/newgame”), this will send a GET request to http://localhost:8080/newgame.

![proxy](images/lab07/proxy.png)

![proxy2](images/lab07/proxy2.png)

### JSON
JSON (JavaScript Object Notation) is a way of formatting data to be easily stored and read by humans. This is similar to a dictionary object with keys and values. An example JSON object is shown below:

![jsonFormat](images/lab07/jsonFormat.png)

This is the format of the information sent from the backend to the frontend.


Loading

0 comments on commit 47b94af

Please sign in to comment.