Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reversi #2323

Merged
merged 1 commit into from
Jul 11, 2024
Merged

Reversi #2323

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Reversi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# **ReverAI Chrome Extension**

---

<br>

# **Description 📃**
<!-- add your game description here -->
- The ReverAI Chrome extension is designed to enhance your browsing experience by providing personalized recommendations, content summaries, and easy Google login for seamless access. It leverages AI to understand your preferences and deliver tailored content.

# **Functionalities 🎮**
<!-- add functionalities over here -->
- Google login for quick and easy access to the extension.
- Personalized content recommendations based on your browsing history.
- Summarization of articles and web pages to quickly grasp key information.
- User-friendly interface with a clean and intuitive design.
<br>

# **How to Use? 🕹️**
<!-- add the steps how to use extension -->
- Install the ReverAI Chrome extension from the Chrome Web Store.
- Click on the extension icon to open the popup.
- Click the "Login with Google" button to sign in.
- Once logged in, you will start receiving personalized content recommendations.
- Browse the web as usual, and ReverAI will provide summaries and recommendations based on your preferences.
- Use the extension popup to view and manage your recommended content.

<br>







16 changes: 16 additions & 0 deletions Reversi/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"manifest_version": 3,
"name": "Reversi Game",
"description": "Play Reversi (Othello) in your browser",
"version": "1.0",
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
}
},
"permissions": ["activeTab"]
}

14 changes: 14 additions & 0 deletions Reversi/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reversi Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Reversi Game</h1>
<div id="board"></div>
<script src="script.js"></script>
</body>
</html>
82 changes: 82 additions & 0 deletions Reversi/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
document.addEventListener('DOMContentLoaded', () => {
const board = document.getElementById('board');
const SIZE = 8;
let currentPlayer = 'B';

const createBoard = () => {
board.innerHTML = '';
for (let i = 0; i < SIZE; i++) {
for (let j = 0; j < SIZE; j++) {
const square = document.createElement('div');
square.classList.add('square');
square.dataset.row = i;
square.dataset.col = j;

if ((i === 3 && j === 3) || (i === 4 && j === 4)) {
square.classList.add('white');
} else if ((i === 3 && j === 4) || (i === 4 && j === 3)) {
square.classList.add('black');
}

square.addEventListener('click', () => handleMove(square));
board.appendChild(square);
}
}
};

const handleMove = (square) => {
const row = parseInt(square.dataset.row);
const col = parseInt(square.dataset.col);

if (square.classList.contains('black') || square.classList.contains('white')) {
return;
}

const directions = [
[-1, 0], [1, 0], [0, -1], [0, 1], // vertical and horizontal
[-1, -1], [-1, 1], [1, -1], [1, 1] // diagonals
];

let validMove = false;

directions.forEach(([dx, dy]) => {
let x = row + dx;
let y = col + dy;
let hasOpponentPiece = false;

while (x >= 0 && x < SIZE && y >= 0 && y < SIZE) {
const targetSquare = document.querySelector(`[data-row='${x}'][data-col='${y}']`);

if (targetSquare.classList.contains(currentPlayer === 'B' ? 'white' : 'black')) {
hasOpponentPiece = true;
} else if ((targetSquare.classList.contains(currentPlayer === 'B' ? 'black' : 'white')) && hasOpponentPiece) {
let flipX = row;
let flipY = col;

while (flipX !== x || flipY !== y) {
const flipSquare = document.querySelector(`[data-row='${flipX}'][data-col='${flipY}']`);
flipSquare.classList.remove('black', 'white');
flipSquare.classList.add(currentPlayer === 'B' ? 'black' : 'white');
flipX += dx;
flipY += dy;
}

validMove = true;
break;
} else {
break;
}

x += dx;
y += dy;
}
});

if (validMove) {
square.classList.add(currentPlayer === 'B' ? 'black' : 'white');
currentPlayer = currentPlayer === 'B' ? 'W' : 'B';
}
};

createBoard();
});
34 changes: 34 additions & 0 deletions Reversi/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
body {
display: flex;
flex-direction: column;
align-items: center;
font-family: Arial, sans-serif;
}

#board {
display: grid;
grid-template-columns: repeat(8, 50px);
grid-template-rows: repeat(8, 50px);
gap: 2px;
margin-top: 20px;
}

.square {
width: 50px;
height: 50px;
background-color: green;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
color: white;
cursor: pointer;
}

.square.black {
background-color: black;
}

.square.white {
background-color: white;
}
Loading