Skip to content

Commit

Permalink
Merge pull request #537 from ABarpanda/main
Browse files Browse the repository at this point in the history
Fixed some issues in chess.py
  • Loading branch information
DhanushNehru authored Jun 30, 2024
2 parents f31a98e + af6eea4 commit 158a703
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 29 deletions.
7 changes: 4 additions & 3 deletions Book-cricket-game/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ This is a simple cricket game implemented using HTML, CSS, and JavaScript. In th
## How to Play

1. Click the "Hit!" button to generate a random number between 0 and 9.
2. If the generated number is 0, the batter is out.
2. If the generated number is 0 or 5, the batter is out.
3. If the generated number is 1, 2, 3, 4, or 6, those runs will be added to the batting team's score.
4. Keep hitting to accumulate runs and try to avoid getting out.
5. Enjoy the game and see how high you can score!
4. If the generated number is 7, 8, or 9, it will be considered as wide.
5. Keep hitting to accumulate runs and try to avoid getting out.
6. Enjoy the game and see how high you can score!

## Technologies Used

Expand Down
23 changes: 19 additions & 4 deletions Book-cricket-game/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,27 @@
<title>Cricket Game</title>
</head>
<body>
<div class="container">
<div class="top">
<h1>Cricket Game</h1>
<button onclick="hit()">Hit!</button>
<h2>Runs: <span id="score">0</span></h2>
<h2>Outs: <span id="outs">0</span></h2>
</div>
<br><br>
<div class="container">
<!--<h1><u>Player 1</u></h1>-->
<button onclick="hit1()" id="hit1">Hit!</button>
<h2>Runs: <span id="score1">0</span></h2>
<h2>Outs: <span id="outs1">0</span></h2>
<h1>Runs on this ball: <span id="current1">0</span></h1>
<p>If the runs you hit on this ball is greater than 6, it will treated as a wide for you.</p>
</div>
<!--
<div class="container">
<h1><u>Player 2</u></h1>
<button onclick="hit2()" id="hit2">Hit!</button>
<h2>Runs: <span id="score2">0</span></h2>
<h2>Outs: <span id="outs2">0</span></h2>
<h1>Runs on this ball: <span id="current2">0</span></h1>
<p>If the runs you hit on this ball is greater than 6, it will treated as a wide for you.</p>
</div>-->
<script src="script.js"></script>
</body>
</html>
61 changes: 49 additions & 12 deletions Book-cricket-game/script.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
let runs = 0;
let outs = 0;
let runs1 = 0;
let outs1 = 0;
let runs2 = 0;
let outs2 = 0;

function hit() {
const randomNumber = Math.floor(Math.random() * 10); // Generates random number between 0 and 9
if (randomNumber === 0) {
outs++;
} else if (randomNumber === 1 || randomNumber === 2 || randomNumber === 3 || randomNumber === 4 || randomNumber === 6) {
runs += randomNumber;
function hit1() {
const randomNumber1 = Math.floor(Math.random() * 10); // Generates random number between 0 and 9
if (randomNumber1 === 0 || randomNumber1 === 5) {
outs1++;
} else if (randomNumber1 === 1 || randomNumber1 === 2 || randomNumber1 === 3 || randomNumber1 === 4 || randomNumber1 === 6) {
runs1 += randomNumber1;
} else {
runs1 += 1;
current1 = 0;
}
updateScore();
current1 = randomNumber1;
updateScore1();
}

function updateScore() {
document.getElementById("score").textContent = runs;
document.getElementById("outs").textContent = outs;
function updateScore1() {
document.getElementById("score1").textContent = runs1;
document.getElementById("outs1").textContent = outs1;
document.getElementById("current1").textContent = current1;
}

// function hit2() {
// const randomNumber2 = Math.floor(Math.random() * 10); // Generates random number between 0 and 9
// if (randomNumber2 === 0 || randomNumber2 === 5) {
// outs2++;
// } else if (randomNumber2 === 1 || randomNumber2 === 2 || randomNumber2 === 3 || randomNumber2 === 4 || randomNumber2 === 6) {
// runs2 += randomNumber2;
// } else {
// runs2 += 1;
// current2 = 0;
// }
// current2 = randomNumber2;
// updateScore2();
// }

// function updateScore2() {
// document.getElementById("score2").textContent = runs2;
// document.getElementById("outs2").textContent = outs2;
// document.getElementById("current2").textContent = current2;
// }

// if (outs1>=10 || outs2>=10){
// if (runs1 === runs2){
// return ("The game is a tie")
// } else if (runs1 > runs2) {
// return ("Player 1 is the winner")
// } else {
// return ("Player 2 is the winner")
// }
// }
20 changes: 16 additions & 4 deletions Book-cricket-game/styles.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
body {
display: flex;
/*display: flex;
justify-content: center;
align-items: center;
height: 100vh;
height: 100vh;*/
margin: 0;
background-color: #f0f0f0;
}

.top{
text-align: center;
width: 100%;
background-color: rgba(0, 255, 255, 0.217);
float: left;
}
.container {
text-align: center;
float: left;
/*width: 49.88%;*/
width: 100%;
height: 632px;
background-color: burlywood;
padding-top: 120px;
border-style: dashed;
border-width: 1px;
}

button {
margin-top: 20px;
padding: 10px 20px;
Expand Down
13 changes: 7 additions & 6 deletions Chess/chess.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Game:
#ive decided since the number of pieces is capped but the type of pieces is not (pawn transformations), I've already coded much of the modularity to support just using a dictionary of pieces
def __init__(self):
self.playersturn = BLACK
self.playersturn = WHITE
self.message = "this is where prompts will go"
self.gameboard = {}
self.placePieces()
Expand All @@ -26,7 +26,7 @@ def placePieces(self):

for i in range(0,8):
self.gameboard[(i,0)] = placers[i](WHITE,uniDict[WHITE][placers[i]])
self.gameboard[((7-i),7)] = placers[i](BLACK,uniDict[BLACK][placers[i]])
self.gameboard[(i,7)] = placers[i](BLACK,uniDict[BLACK][placers[i]])
placers.reverse()


Expand Down Expand Up @@ -69,7 +69,7 @@ def isCheck(self):
for position,piece in self.gameboard.items():
if type(piece) == King:
kingDict[piece.Color] = position
print(piece)
#print(piece)
pieceDict[piece.Color].append((piece,position))
#white
if self.canSeeKing(kingDict[WHITE],pieceDict[BLACK]):
Expand All @@ -86,8 +86,8 @@ def canSeeKing(self,kingpos,piecelist):

def parseInput(self):
try:
a,b = input().split()
a = ((ord(a[0])-97), int(a[1])-1)
a,b = input("Input your move --> ").split()
a = (ord(a[0])-97, int(a[1])-1)
b = (ord(b[0])-97, int(b[1])-1)
print(a,b)
return (a,b)
Expand Down Expand Up @@ -222,7 +222,8 @@ def availableMoves(self,x,y,gameboard, Color = None):
answers = []
if (x+1,y+self.direction) in gameboard and self.noConflict(gameboard, Color, x+1, y+self.direction) : answers.append((x+1,y+self.direction))
if (x-1,y+self.direction) in gameboard and self.noConflict(gameboard, Color, x-1, y+self.direction) : answers.append((x-1,y+self.direction))
if (x,y+self.direction) not in gameboard and Color == self.Color : answers.append((x,y+self.direction))# the condition after the and is to make sure the non-capturing movement (the only fucking one in the game) is not used in the calculation of checkmate
if (x,y+self.direction) not in gameboard and Color == self.Color and y<7: answers.append((x,y+self.direction))# the condition after the and is to make sure the non-capturing movement (the only one in the game) is not used in the calculation of checkmate
if ((x,y+2*self.direction) and (x,y+self.direction)) not in gameboard and Color == self.Color and (y==1 or y==6) : answers.append((x,y+2*self.direction))
return answers

uniDict = {WHITE : {Pawn : "♙", Rook : "♖", Knight : "♘", Bishop : "♗", King : "♔", Queen : "♕" }, BLACK : {Pawn : "♟", Rook : "♜", Knight : "♞", Bishop : "♝", King : "♚", Queen : "♛" }}
Expand Down

0 comments on commit 158a703

Please sign in to comment.