Skip to content

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
Deployment
  • Loading branch information
alenmonti authored Dec 11, 2023
2 parents c5942d1 + 3a84bc8 commit 3a22ce7
Show file tree
Hide file tree
Showing 168 changed files with 5,419 additions and 51 deletions.
42 changes: 39 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ Play truco on truco.com, the best card game to play 1v1
* React + Tailwind for the frontend
* MongoDB (MongoAtlas) for the no-sql database

1. **Node**: A asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications[^1].
1. **Express**: Minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications[^2].
1. **React**: A JavaScript library for building user interfaces[^3].
1. **Tailwind**: A utility-first CSS framework packed with classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup[^4].
1. **MongoDB**: A fully-managed cloud database that handles all the complexity of deploying, managing, and healing your deployments on the cloud service provider of your choice (AWS , Azure, and GCP)[^5].
1. **Pusher**: Pusher Channels is a hosted WebSockets(helps communication between client and server) solution for building powerful realtime interactive apps[^6].

## Extra

### [Contribution Standards](./docs/CONTRIBS.md)
Expand All @@ -27,16 +34,38 @@ Play truco on truco.com, the best card game to play 1v1

### [Game Rules](./docs/RULES.md)

## How to run locally (linux)
### [Api Documentation](./docs/API.md)

## How to run locally

**(BETTER FOR DEVELOPMENT)** Run two servers in two different terminals one for the [backend](./truco-back/README.md) and another one for the [frontend](./truco-front/README.md). *(click the links to see how)*

Alternatively if you want to **test a prod-like** version of the app locally use the following commands (this integrates the frontend and backend together)

```shell
./run-locally.sh
./run-locally.sh # LINUX. Runs the whole app in one prod-like local server
./run-locally.ps1 # WINDOWS. Runs the whole app in one prod-like local server
```

## How to run with docker (recommended)

## How to run with docker (prod ready)
remove sudo if running on windows
```shell

optional
********************************************************************
#to check if docker is installed (linux)
docker --version

#to install docker if it isn't installed
Linux:
sudo snap install docker # version 20.10.24, or
sudo apt install docker.io # version 24.0.5-0ubuntu1~20.04.1

windows:
https://docs.docker.com/desktop/install/windows-install/
********************************************************************

sudo docker build -t truco-img .
sudo docker run -p 8080:8080 --name truco-app truco-img

Expand All @@ -48,3 +77,10 @@ sudo docker start truco-app
```

Thanks for passing by!

[^1]: [Nodejs documentation](https://nodejs.org/en/about)
[^2]: [Expressjs documentation](https://expressjs.com/)
[^3]: [Reactjs documentation](https://legacy.reactjs.org/)
[^4]: [Tailwind documentation](https://tailwindcss.com/)
[^5]: [MongoDB documentation](https://www.mongodb.com/basics/mongodb-atlas-tutorial#:~:text=MongoDB%20Atlas%20is%20a%20fully,scale%20MongoDB%20in%20the%20cloud.)
[^6]: [Pusher documentation](https://pusher.com/websockets/)
26 changes: 0 additions & 26 deletions build-front2back.sh

This file was deleted.

54 changes: 54 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Api Documentation

## Endpoints

### Websockets

* POST `/api/pusher`

### User auth

* POST `/api/auth/register` -> if 201 returns a User
* POST `/api/auth/login` -> if 200 returns a User

```json
- same request body for both POST endpoints:
{
"username": "letters and numbers only",
"password": "letters, numbers and special characters except spaces"
}
```

* GET `/api/auth/session` -> if 200 returns a User
* GET `/api/auth/logout`

### Friend requests

* GET `/api/friends/friendRequest/:targetUsername`
* GET `/api/friends/acceptFriendRequest/:targetUsername`

### Stats

* PUT `/api/stats/addWin`
* PUT `/api/stats/addLoss`
* PUT `/api/stats/updateRating`

```json
- request body for updateRating (the rest can be an empty body)
{
"ratingDifferential": 27 // it can be a possitive number to add rating or negative to substract
}
```

## Models

### User

* _id: string
* username: string
* password: string
* rating: number
* wins: number
* losses: number
* friends: User[]
* friendRequests: User[]
92 changes: 90 additions & 2 deletions docs/RULES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,93 @@
# Game rules
# Truco Rules

## Game

Truco is a card game played between two players (or in pairs) with a spanish deck (40 cards) wihout 8s, 9s or jokers. There are three ways of scoring points:

* **Flor**: the players compare three cards of the same suits.
* **Envido**: the players compare two cards of the same suits.
* **Truco**: the cards are compared individually.

After the **Flor** and **Envido**, the game is divided in three rounds. In each round, each player chooses one of the cards in their hand to compete against the card of the other player. The winner is the one who wins two rounds out of three.

The player who first reaches 30 points(or 15 points depending the variant of the game) in total wins the match.

## Truco

The players can make a bet called "**Truco**" any time in the game. If **Truco** is called and accepted, the players lose the chance to call **Envido**, but the other player can call envido over the truco call invalidating it (although it can be called again after envido). If there is no bet one point goes to the winner of the round. The players can raise the bet only one time in this order:

* **Truco**: 2 points.
* **Retruco**: 3 points.
* **Vale 4**: 4 points.

Players can accept, reject or raise the bet:

* **accept**: the points in dispute go to the winner of the round.
* **reject**: the player loses the round and the points go to the other player.
* **raise**: the player can raise the bet in this sequence.


no bet -> truco -> retruco -> quiero vale 4

## Envido

At the beginning of the round, a player in his turn can call for **envido** then an option will apear for the other player to respond to this bet in any of these ways:

* **Quiero**: accepts to take the bet.
* **Envido**: raise the bet by 2 points.
* **Real envido**: raise the bet by 3 points.
* **Falta envido**: if accepted the one who wins, wins the game.
* **No quiero** - refuses to take the last bet.

the hierarchy of envido bet is as follows:

no bet -> envido -> real envido -> falta envido

if a player raises envido bet the other can't go back.
An example of a envido bet could be like this:

envido (player 1) -> envido (player 2) -> real envido (player 1) -> quiero (player 2)
The player who has the best pair will win 7 points (2 + 2 + 3).

Another example with _No quiero_ could be:

envido (player 1) -> envido (player 2) -> real envido (player 1) -> falta envido (player 1) -> no quiero (player 2)
player 1 wins 7 points (2 + 2 + 3).

A player can make any of the envido bets first, for example a player could start with real envido. If any of this bets is rejected wihout a raise the winner obtains 1 point. Players can't call **real envido** or **falta envido** more than one time.

If no one calls for envido, there is no score for it.
The cards are counted as follow:
* same suit: the sum of the two cards + 20 (10,11 and 12 add no value).
* all different suits: the value of the highest card in the hand.

the highest envido is worth 33 (7-6 of the same suit) and the lowest 0 (11-13 different suits; 10, 11 and 12 add no value).
The players compare the two cards they have chosen and whoever has the highest score wins the points of envido. If there is a tie the winner is the hand-player.

## Flor

A player whose three cards are of the same suit is said to have a Flor (flower), and must announce this, saying "flor". If more than one person has a Flor, and all of these are simply announced by saying "flor", the team of the person with the best Flor scores 3 points for each Flor that was announced.
The value of flor is the same as the "envido" (sum three cards + 20 if same suit and 10, 11 and 12 have no value).

* **Flor**: 3 points (one player has flor and the other doesn't).
* **Contra Flor**: if it is accepted 6 points to the winner, else 4 points (can be called only if both sides have flor).



## Card Values

![trucoCards](https://github.com/maxogod/Truco/assets/85034225/627d81df-2c5d-404a-9927-695783b62e58)

### Sources

1. [wikipedia truco](https://en.wikipedia.org/wiki/Truco)
1. [argentinian truco rules](https://www.pagat.com/put/truco_ar.html)
1. [description truco in city Buenos Aires page](https://turismo.buenosaires.gob.ar/en/article/get-tricks-%E2%80%9Ctruco%E2%80%9D)
1. [rules truco in a online game](https://www.mundigames.com/multiplayer/argentinian-truco/rules/)
1. Truco blyts app


Implement me

[go to readme](../README.md)
47 changes: 47 additions & 0 deletions run-locally.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

# BUILD FRONT AND COPY IT TO BACKEND/SRC/PUBLIC

# Navigate to the frontend directory
cd .\truco-front

# Install packages
npm install

# Run the npm build script
npm run build

# Check if the build was successful
if ($LASTEXITCODE -eq 0) {
Write-Host "Frontend build successful. Copying files to backend."

# Navigate back to the original directory
cd ..

# Remove existing files in backend/src/public/
if (Test-Path ".\truco-back\src\public\") {
Remove-Item -Recurse -Force .\truco-back\src\public\
}

# Copy the contents of frontend/dist to backend/src/public
xcopy /y /s /e .\truco-front\dist\* .\truco-back\src\public\

Write-Host "Copy completed."
} else {
Write-Host "Frontend build failed. Aborting copy to backend."
}

# COMPILE BACKEND AND RUN IT

cd ./truco-back

npm install

npm run build-windows

if ($LASTEXITCODE -eq 0) {
Write-Host "Backend build successful. Starting server."

npm run start
} else {
Write-Host "Backend build failed. Aborting server start."
}
29 changes: 28 additions & 1 deletion run-locally.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
#!/bin/bash

./build-front2back.sh
# BUILD FRONT AND COPY IT TO BACKEND/SRC/PUBLIC

# Navigate to the frontend directory
cd ./truco-front

# install packages
npm install

# Run the npm build script
npm run build

# Check if the build was successful
if [ $? -eq 0 ]; then
echo "Frontend build successful. Copying files to backend."

# Navigate back to the original directory
cd ..

rm -rf ./truco-back/src/public/
# Copy the contents of frontend/dist to backend/src/public
cp -r ./truco-front/dist/ ./truco-back/src/public/

echo "Copy completed."
else
echo "Frontend build failed. Aborting copy to backend."
fi

# COMPILE BACKEND AND RUN IT

# Navigate to the backend directory
cd ./truco-back
Expand Down
9 changes: 7 additions & 2 deletions truco-back/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
## How to run

```shell
npm run build # compile code
npm install # if you didn't install the modules yet

npm run start # run compiled prod-ready server
npm run build # compile code
npm run build-windows # For windows

npm run dev # run development server (IMPORTANT, to run this command the code must have been compiled at least once otherwise it won't work)

npm run start # run compiled prod-ready server (runs whatever is built)
```

[go to readme](../README.md)
Loading

0 comments on commit 3a22ce7

Please sign in to comment.