Skip to content

Day06 #12

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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.DS_STORE
.history/
.history/
.history/*
.lh
.lh
.terraform/
.vagrant/
*:Zone*
*.excalidrawlib*
*.tfstate
*.tfstate.*
*.tfvars
/.lh/*
~*
node_modules/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "day02/4-in-a-row"]
path = day02/4-in-a-row
url = https://github.com/idubi/4-in-a-row.git
[submodule "Resources/Day02/4-in-a-row"]
path = Resources/Day02/4-in-a-row
url = https://github.com/idubi/4-in-a-row.git
6 changes: 6 additions & 0 deletions .lh/.lhignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# list file to not track by the local-history extension. comment line starts with a '#' character
# each line describe a regular expression pattern (search for 'Javascript regex')
# it will relate to the workspace directory root. for example:
# '.*\.txt' ignores any file with 'txt' extension
# '/test/.*' ignores all the files under the 'test' directory
# '.*/test/.*' ignores all the files under any 'test' directory (even under sub-folders)
22 changes: 22 additions & 0 deletions .lh/Resources/Day01/Dockerfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"sourceFile": "Resources/Day01/Dockerfile",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 1,
"patches": [
{
"date": 1744972060115,
"content": "Index: \n===================================================================\n--- \n+++ \n"
},
{
"date": 1744972109343,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -2,6 +2,6 @@\n WORKDIR /app\n COPY . .\n RUN yarn install --production\n CMD [ \"node\", \"src/index.js\" ]\n+EXPOSE 3000\n \n-\n"
}
],
"date": 1744972060115,
"name": "Commit-0",
"content": "FROM node:18-alpine\nWORKDIR /app\nCOPY . .\nRUN yarn install --production\nCMD [ \"node\", \"src/index.js\" ]\n\n\n"
}
]
}
22 changes: 22 additions & 0 deletions .lh/Resources/Day01/shlif.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"sourceFile": "Resources/Day01/shlif",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 1,
"patches": [
{
"date": 1744973093696,
"content": "Index: \n===================================================================\n--- \n+++ \n"
},
{
"date": 1744983740930,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,2 +1,10 @@\n-docker tag local-image:tagname new-repo:tagname\n+\n+cd Resources/Day02/\n+git branch -m day01 day02\n+mv ../Day01/Dockerfile .\n+docker build . -t day02-node18alpine\n+\n+\n+\n+docker tag day02.node18alpin:idubi/40.days.of.k8s:1.0\n docker push new-repo:tagname\n"
}
],
"date": 1744973093696,
"name": "Commit-0",
"content": "docker tag local-image:tagname new-repo:tagname\ndocker push new-repo:tagname\n"
}
]
}
18 changes: 18 additions & 0 deletions .lh/Resources/Day02/4InARow/index.css.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"sourceFile": "Resources/Day02/4InARow/index.css",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 0,
"patches": [
{
"date": 1744992036876,
"content": "Index: \n===================================================================\n--- \n+++ \n"
}
],
"date": 1744992036876,
"name": "Commit-0",
"content": "@tailwind base;\n@tailwind components;\n@tailwind utilities;"
}
]
}
18 changes: 18 additions & 0 deletions .lh/Resources/Day02/4InARow/index.html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"sourceFile": "Resources/Day02/4InARow/index.html",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 0,
"patches": [
{
"date": 1744992049899,
"content": "Index: \n===================================================================\n--- \n+++ \n"
}
],
"date": 1744992049899,
"name": "Commit-0",
"content": "html\n<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>4 in a Row</title>\n </head>\n <body>\n <div id=\"root\"></div>\n </body>\n</html>"
}
]
}
22 changes: 22 additions & 0 deletions .lh/Resources/Day02/4InARow/index.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"sourceFile": "Resources/Day02/4InARow/index.js",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 1,
"patches": [
{
"date": 1744992013030,
"content": "Index: \n===================================================================\n--- \n+++ \n"
},
{
"date": 1744992020013,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,6 +1,13 @@\n-module.exports = {\n- plugins: {\n- tailwindcss: {},\n- autoprefixer: {},\n- }\n-}\n\\ No newline at end of file\n+import React from 'react';\n+import ReactDOM from 'react-dom/client';\n+import './index.css';\n+import Layout from './Layout';\n+\n+const root = ReactDOM.createRoot(document.getElementById('root'));\n+root.render(\n+ <React.StrictMode>\n+ <Layout>\n+ {/* Add your game components here */}\n+ </Layout>\n+ </React.StrictMode>\n+);\n\\ No newline at end of file\n"
}
],
"date": 1744992013030,
"name": "Commit-0",
"content": "module.exports = {\n plugins: {\n tailwindcss: {},\n autoprefixer: {},\n }\n}"
}
]
}
26 changes: 26 additions & 0 deletions .lh/Resources/Day02/4InARow/package.json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"sourceFile": "Resources/Day02/4InARow/package.json",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 2,
"patches": [
{
"date": 1744991842743,
"content": "Index: \n===================================================================\n--- \n+++ \n"
},
{
"date": 1744993658680,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -4,9 +4,17 @@\n \"private\": true,\n \"dependencies\": {\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n- \"react-scripts\": \"5.0.1\"\n+ \"react-scripts\": \"5.0.1\",\n+ \"framer-motion\": \"^10.16.0\",\n+ \"lucide-react\": \"^0.284.0\",\n+ \"@radix-ui/react-select\": \"^1.2.2\",\n+ \"@radix-ui/react-label\": \"^2.0.2\",\n+ \"@radix-ui/react-slot\": \"^1.0.2\",\n+ \"class-variance-authority\": \"^0.7.0\",\n+ \"clsx\": \"^2.0.0\",\n+ \"tailwind-merge\": \"^1.14.0\"\n },\n \"devDependencies\": {\n \"autoprefixer\": \"^10.4.14\",\n \"postcss\": \"^8.4.27\",\n"
},
{
"date": 1745045667253,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -31,8 +31,13 @@\n \"react-app\",\n \"react-app/jest\"\n ]\n },\n+ \"paths\": {\n+ \"@/*\": [\n+ \"./src/*\"\n+ ]\n+ },\n \"browserslist\": {\n \"production\": [\n \">0.2%\",\n \"not dead\",\n"
}
],
"date": 1744991842743,
"name": "Commit-0",
"content": "{\n \"name\": \"4-in-a-row\",\n \"version\": \"1.0.0\",\n \"private\": true,\n \"dependencies\": {\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"react-scripts\": \"5.0.1\"\n },\n \"devDependencies\": {\n \"autoprefixer\": \"^10.4.14\",\n \"postcss\": \"^8.4.27\",\n \"tailwindcss\": \"^3.3.3\"\n },\n \"scripts\": {\n \"start\": \"react-scripts start\",\n \"build\": \"react-scripts build\",\n \"test\": \"react-scripts test\",\n \"eject\": \"react-scripts eject\"\n },\n \"eslintConfig\": {\n \"extends\": [\n \"react-app\",\n \"react-app/jest\"\n ]\n },\n \"browserslist\": {\n \"production\": [\n \">0.2%\",\n \"not dead\",\n \"not op_mini all\"\n ],\n \"development\": [\n \"last 1 chrome version\",\n \"last 1 firefox version\",\n \"last 1 safari version\"\n ]\n }\n}\n"
}
]
}
18 changes: 18 additions & 0 deletions .lh/Resources/Day02/4InARow/postcss.config.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"sourceFile": "Resources/Day02/4InARow/postcss.config.js",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 0,
"patches": [
{
"date": 1744991956786,
"content": "Index: \n===================================================================\n--- \n+++ \n"
}
],
"date": 1744991956786,
"name": "Commit-0",
"content": "module.exports = {\n plugins: {\n tailwindcss: {},\n autoprefixer: {},\n }\n}"
}
]
}
18 changes: 18 additions & 0 deletions .lh/Resources/Day02/4InARow/src/Components/GameBoard.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"sourceFile": "Resources/Day02/4InARow/src/Components/GameBoard.js",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 0,
"patches": [
{
"date": 1744993231081,
"content": "Index: \n===================================================================\n--- \n+++ \n"
}
],
"date": 1744993231081,
"name": "Commit-0",
"content": "import React from 'react';\nimport Cell from './Cell';\nimport { Button } from \"@/components/ui/button\";\nimport { RotateCcw, Trophy, MinusCircle, Lightbulb, PlusCircle } from \"lucide-react\";\nimport { motion } from \"framer-motion\";\nimport { Badge } from \"@/components/ui/badge\";\n\nexport default function GameBoard({ \n board, \n onCellClick, \n gameOver, \n winner,\n winningCells,\n onRestart,\n onNewGame,\n currentPlayer,\n isThinking,\n hintsLeft,\n onHint,\n hintColumn\n}) {\n return (\n <div className=\"max-w-3xl mx-auto p-4\">\n <div className=\"flex justify-between items-center mb-6\">\n <div className=\"flex items-center gap-4\">\n {gameOver ? (\n <motion.div\n initial={{ scale: 0 }}\n animate={{ scale: 1 }}\n className={`inline-block px-4 py-2 rounded-full font-semibold ${\n winner === 0 \n ? \"bg-blue-100 text-blue-800\" \n : \"bg-green-100 text-green-800\"\n }`}\n >\n {winner === 0 ? (\n <>\n <MinusCircle className=\"w-5 h-5 inline mr-2\" />\n It's a tie!\n </>\n ) : (\n <>\n <Trophy className=\"w-5 h-5 inline mr-2\" />\n {winner === 1 ? \"You won!\" : \"AI won!\"}\n </>\n )}\n </motion.div>\n ) : (\n <div className=\"text-lg font-medium text-gray-700\">\n {isThinking ? \"AI is thinking...\" : \"Your turn\"}\n </div>\n )}\n </div>\n\n <div className=\"flex items-center gap-2\">\n {!gameOver && currentPlayer === 1 && hintsLeft > 0 && (\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={onHint}\n className=\"gap-2\"\n disabled={isThinking}\n >\n <Lightbulb className=\"w-4 h-4\" />\n Hint ({hintsLeft})\n </Button>\n )}\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={onNewGame}\n className=\"gap-2\"\n >\n <PlusCircle className=\"w-4 h-4\" />\n New Game\n </Button>\n </div>\n </div>\n\n <div className=\"bg-white rounded-xl shadow-lg p-4\">\n <div \n className=\"grid gap-2\"\n style={{ \n gridTemplateColumns: `repeat(${board[0].length}, minmax(0, 1fr))` \n }}\n >\n {board.map((row, i) =>\n row.map((cell, j) => (\n <Cell\n key={`${i}-${j}`}\n value={cell}\n isValid={!gameOver && !isThinking && currentPlayer === 1 && !board[0][j]}\n isWinning={winningCells?.some(([x, y]) => x === i && y === j)}\n isHint={hintColumn === j}\n onClick={() => onCellClick(j)}\n />\n ))\n )}\n </div>\n </div>\n\n {gameOver && (\n <div className=\"text-center mt-6\">\n <Button \n onClick={onRestart}\n variant=\"outline\"\n className=\"gap-2\"\n >\n <RotateCcw className=\"w-4 h-4\" />\n Play Again\n </Button>\n </div>\n )}\n </div>\n );\n}"
}
]
}
26 changes: 26 additions & 0 deletions .lh/Resources/Day02/4InARow/src/Pages/Game.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"sourceFile": "Resources/Day02/4InARow/src/Pages/Game.js",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 2,
"patches": [
{
"date": 1744993333648,
"content": "Index: \n===================================================================\n--- \n+++ \n"
},
{
"date": 1744993474128,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,8 +1,8 @@\n import React, { useState, useEffect } from 'react';\n import GameSettings from '../components/game/GameSettings';\n import GameBoard from '../components/game/GameBoard';\n-import GameAI, { findBestMove, makeMove, checkWinner } from '../components/gameAI';\n+import { findBestMove, makeMove, checkWinner } from '../components/gameAI';\n \n export default function Game() {\n const [gameStarted, setGameStarted] = useState(false);\n const [board, setBoard] = useState(null);\n"
},
{
"date": 1744993549762,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,7 +1,7 @@\n import React, { useState, useEffect } from 'react';\n-import GameSettings from '../components/game/GameSettings';\n-import GameBoard from '../components/game/GameBoard';\n+import GameSettings from '../components/GameSettings';\n+import GameBoard from '../components/GameBoard';\n import { findBestMove, makeMove, checkWinner } from '../components/gameAI';\n \n export default function Game() {\n const [gameStarted, setGameStarted] = useState(false);\n"
}
],
"date": 1744993333648,
"name": "Commit-0",
"content": "import React, { useState, useEffect } from 'react';\nimport GameSettings from '../components/game/GameSettings';\nimport GameBoard from '../components/game/GameBoard';\nimport GameAI, { findBestMove, makeMove, checkWinner } from '../components/gameAI';\n\nexport default function Game() {\n const [gameStarted, setGameStarted] = useState(false);\n const [board, setBoard] = useState(null);\n const [currentPlayer, setCurrentPlayer] = useState(1);\n const [gameOver, setGameOver] = useState(false);\n const [winner, setWinner] = useState(null);\n const [winningCells, setWinningCells] = useState(null);\n const [settings, setSettings] = useState(null);\n const [isThinking, setIsThinking] = useState(false);\n const [hintsLeft, setHintsLeft] = useState(0);\n const [hintColumn, setHintColumn] = useState(null);\n\n const initializeBoard = (rows, cols) => {\n return Array(rows).fill().map(() => Array(cols).fill(0));\n };\n\n const handleStartGame = (gameSettings) => {\n setSettings(gameSettings);\n setBoard(initializeBoard(gameSettings.rows, gameSettings.cols));\n setGameStarted(true);\n setCurrentPlayer(1);\n setGameOver(false);\n setWinner(null);\n setWinningCells(null);\n setHintsLeft(gameSettings.hints);\n setHintColumn(null);\n };\n\n const checkForTie = (board) => {\n const isFullBoard = board[0].every(cell => cell !== 0);\n if (isFullBoard) {\n return true;\n }\n return false;\n };\n\n const handleHint = () => {\n if (hintsLeft > 0 && currentPlayer === 1 && !gameOver) {\n const { column } = findBestMove(board, settings.level, false, -Infinity, Infinity);\n setHintColumn(column);\n setHintsLeft(prev => prev - 1);\n }\n };\n\n const handleCellClick = (col) => {\n if (gameOver || currentPlayer !== 1) return;\n\n setHintColumn(null);\n const newBoard = makeMove(board, col, 1);\n setBoard(newBoard);\n\n const result = checkWinner(newBoard);\n if (result) {\n setGameOver(true);\n setWinner(result.winner);\n setWinningCells(result.winningCells);\n return;\n }\n\n if (checkForTie(newBoard)) {\n setGameOver(true);\n setWinner(0);\n return;\n }\n\n setCurrentPlayer(2);\n };\n\n useEffect(() => {\n if (currentPlayer === 2 && !gameOver) {\n setIsThinking(true);\n setTimeout(() => {\n const { column } = findBestMove(board, settings.level, true, -Infinity, Infinity);\n const newBoard = makeMove(board, column, 2);\n setBoard(newBoard);\n\n const result = checkWinner(newBoard);\n if (result) {\n setGameOver(true);\n setWinner(result.winner);\n setWinningCells(result.winningCells);\n } else if (checkForTie(newBoard)) {\n setGameOver(true);\n setWinner(0);\n } else {\n setCurrentPlayer(1);\n }\n setIsThinking(false);\n }, 500);\n }\n }, [currentPlayer, board, settings?.level]);\n\n if (!gameStarted) {\n return (\n <div className=\"min-h-screen bg-gradient-to-br from-blue-50 to-purple-50 py-12\">\n <GameSettings onStartGame={handleStartGame} />\n </div>\n );\n }\n\n return (\n <div className=\"min-h-screen bg-gradient-to-br from-blue-50 to-purple-50 py-8\">\n <GameBoard\n board={board}\n onCellClick={handleCellClick}\n gameOver={gameOver}\n winner={winner}\n winningCells={winningCells}\n onRestart={() => handleStartGame(settings)}\n onNewGame={() => setGameStarted(false)}\n currentPlayer={currentPlayer}\n isThinking={isThinking}\n hintsLeft={hintsLeft}\n onHint={handleHint}\n hintColumn={hintColumn}\n />\n </div>\n );\n}"
}
]
}
18 changes: 18 additions & 0 deletions .lh/Resources/Day02/4InARow/src/Row/tailwind.config.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"sourceFile": "Resources/Day02/4InARow/src/Row/tailwind.config.js",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 0,
"patches": [
{
"date": 1744991935123,
"content": "Index: \n===================================================================\n--- \n+++ \n"
}
],
"date": 1744991935123,
"name": "Commit-0",
"content": "module.exports = {\n content: [\n \"./src/**/*.{js,jsx,ts,tsx}\",\n ],\n theme: {\n extend: {},\n },\n plugins: [],\n}"
}
]
}
Loading