MAINT: Apply pre-commit

Remove byte-order-marker pre-commit check as there would be
many adjustments necessary
This commit is contained in:
Martin Thoma
2022-03-05 09:29:23 +01:00
parent f5e33ae38f
commit e64fb6795c
536 changed files with 6267 additions and 5556 deletions

View File

@@ -9,39 +9,39 @@ import java.util.Scanner;
* <p>
* Note: The idea was to create a version of the 1970's BASIC game in Java, without introducing
* new features - no additional text, error checking, etc has been added.
*
*
* Converted from BASIC to Java by Darren Cardenas.
*/
public class OneCheck {
public class OneCheck {
private final Scanner scan; // For user input
private enum Step {
SHOW_INSTRUCTIONS, SHOW_BOARD, GET_MOVE, GET_SUMMARY, QUERY_RETRY
}
}
public OneCheck() {
scan = new Scanner(System.in);
} // End of constructor OneCheck
} // End of constructor OneCheck
public void play() {
showIntro();
startGame();
} // End of method play
} // End of method play
private static void showIntro() {
System.out.println(" ".repeat(29) + "ONE CHECK");
System.out.println(" ".repeat(14) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println("\n\n");
} // End of method showIntro
} // End of method showIntro
private void startGame() {
int fromSquare = 0;
@@ -50,26 +50,26 @@ public class OneCheck {
int square = 0;
int startPosition = 0;
int toSquare = 0;
// Move legality test variables
int fromTest1 = 0;
int fromTest2 = 0;
int toTest1 = 0;
int toTest2 = 0;
int[] positions = new int[65];
Step nextStep = Step.SHOW_INSTRUCTIONS;
String lineContent = "";
String userResponse = "";
String userResponse = "";
// Begin outer while loop
while (true) {
// Begin switch
switch (nextStep) {
case SHOW_INSTRUCTIONS:
System.out.println("SOLITAIRE CHECKER PUZZLE BY DAVID AHL\n");
@@ -82,68 +82,68 @@ public class OneCheck {
System.out.println("CHECKER AND '0' AN EMPTY SQUARE. WHEN YOU HAVE NO");
System.out.println("POSSIBLE JUMPS REMAINING, INPUT A '0' IN RESPONSE TO");
System.out.println("QUESTION 'JUMP FROM ?'\n");
System.out.println("HERE IS THE NUMERICAL BOARD:\n");
System.out.println("HERE IS THE NUMERICAL BOARD:\n");
nextStep = Step.SHOW_BOARD;
break;
case SHOW_BOARD:
// Begin loop through all squares
for (square = 1; square <= 57; square += 8) {
lineContent = String.format("% -4d%-4d%-4d%-4d%-4d%-4d%-4d%-4d", square, square + 1, square + 2,
square + 3, square + 4, square + 5, square + 6, square + 7);
System.out.println(lineContent);
} // End loop through all squares
System.out.println("");
System.out.println("AND HERE IS THE OPENING POSITION OF THE CHECKERS.");
System.out.println("");
System.out.println("");
Arrays.fill(positions, 1);
// Begin generating start positions
for (square = 19; square <= 43; square += 8) {
for (startPosition = square; startPosition <= square + 3; startPosition++) {
positions[startPosition] = 0;
}
}
} // End generating start positions
numJumps = 0;
printBoard(positions);
printBoard(positions);
nextStep = Step.GET_MOVE;
break;
case GET_MOVE:
System.out.print("JUMP FROM? ");
fromSquare = scan.nextInt();
scan.nextLine(); // Discard newline
// User requested summary
if (fromSquare == 0) {
if (fromSquare == 0) {
nextStep = Step.GET_SUMMARY;
break;
break;
}
System.out.print("TO? ");
toSquare = scan.nextInt();
scan.nextLine(); // Discard newline
System.out.println("");
System.out.println("");
// Check legality of move
fromTest1 = (int) Math.floor((fromSquare - 1.0) / 8.0);
fromTest2 = fromSquare - 8 * fromTest1;
toTest1 = (int) Math.floor((toSquare - 1.0) / 8.0);
toTest2 = toSquare - 8 * toTest1;
if ((fromTest1 > 7) ||
(toTest1 > 7) ||
(fromTest2 > 8) ||
@@ -153,49 +153,49 @@ public class OneCheck {
(positions[(toSquare + fromSquare) / 2] == 0) ||
(positions[fromSquare] == 0) ||
(positions[toSquare] == 1)) {
System.out.println("ILLEGAL MOVE. TRY AGAIN...");
nextStep = Step.GET_MOVE;
break;
break;
}
positions[toSquare] = 1;
positions[fromSquare] = 0;
positions[(toSquare + fromSquare) / 2] = 0;
numJumps++;
printBoard(positions);
printBoard(positions);
nextStep = Step.GET_MOVE;
break;
case GET_SUMMARY:
numPieces = 0;
// Count remaining pieces
for (square = 1; square <= 64; square++) {
numPieces += positions[square];
for (square = 1; square <= 64; square++) {
numPieces += positions[square];
}
System.out.println("");
System.out.println("YOU MADE " + numJumps + " JUMPS AND HAD " + numPieces + " PIECES");
System.out.println("REMAINING ON THE BOARD.\n");
nextStep = Step.QUERY_RETRY;
System.out.println("REMAINING ON THE BOARD.\n");
nextStep = Step.QUERY_RETRY;
break;
case QUERY_RETRY:
while (true) {
System.out.print("TRY AGAIN? ");
userResponse = scan.nextLine();
System.out.println("");
if (userResponse.toUpperCase().equals("YES")) {
nextStep = Step.SHOW_BOARD;
break;
}
}
else if (userResponse.toUpperCase().equals("NO")) {
System.out.println("O.K. HOPE YOU HAD FUN!!");
return;
@@ -203,50 +203,50 @@ public class OneCheck {
else {
System.out.println("PLEASE ANSWER 'YES' OR 'NO'.");
}
}
}
break;
default:
System.out.println("INVALID STEP");
nextStep = Step.QUERY_RETRY;
break;
break;
} // End of switch
} // End outer while loop
} // End of method startGame
} // End outer while loop
} // End of method startGame
public void printBoard(int[] positions) {
int column = 0;
int row = 0;
int row = 0;
String lineContent = "";
// Begin loop through all rows
for (row = 1; row <= 57; row += 8) {
// Begin loop through all columns
for (column = row; column <= row + 7; column++) {
lineContent += " " + positions[column];
lineContent += " " + positions[column];
} // End loop through all columns
System.out.println(lineContent);
lineContent = "";
lineContent = "";
} // End loop through all rows
System.out.println("");
System.out.println("");
} // End of method printBoard
public static void main(String[] args) {
OneCheck game = new OneCheck();
game.play();
} // End of method main
} // End of class OneCheck

View File

@@ -12,10 +12,10 @@ function input()
{
var input_element;
var input_str;
return new Promise(function (resolve) {
input_element = document.createElement("INPUT");
print("? ");
input_element.setAttribute("type", "text");
input_element.setAttribute("length", "50");

View File

@@ -2,41 +2,43 @@
# Port to python by imiro
def tab(x):
return ' '*x
return " " * x
def main():
# Initial instructions
print(tab(30) + "ONE CHECK");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
print();
print();
print();
print("SOLITAIRE CHECKER PUZZLE BY DAVID AHL");
print();
print("48 CHECKERS ARE PLACED ON THE 2 OUTSIDE SPACES OF A");
print("STANDARD 64-SQUARE CHECKERBOARD. THE OBJECT IS TO");
print("REMOVE AS MANY CHECKERS AS POSSIBLE BY DIAGONAL JUMPS");
print("(AS IN STANDARD CHECKERS). USE THE NUMBERED BOARD TO");
print("INDICATE THE SQUARE YOU WISH TO JUMP FROM AND TO. ON");
print("THE BOARD PRINTED OUT ON EACH TURN '1' INDICATES A");
print("CHECKER AND '0' AN EMPTY SQUARE. WHEN YOU HAVE NO");
print("POSSIBLE JUMPS REMAINING, INPUT A '0' IN RESPONSE TO");
print("QUESTION 'JUMP FROM ?'");
print();
print("HERE IS THE NUMERICAL BOARD:");
print();
while(True):
for j in range(1,64,8):
for i in range(j,j+7):
print(i, end=(' '*(3 if i < 10 else 2)))
print(j+7)
# Initial instructions
print(tab(30) + "ONE CHECK")
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
print()
print()
print()
print("SOLITAIRE CHECKER PUZZLE BY DAVID AHL")
print()
print("48 CHECKERS ARE PLACED ON THE 2 OUTSIDE SPACES OF A")
print("STANDARD 64-SQUARE CHECKERBOARD. THE OBJECT IS TO")
print("REMOVE AS MANY CHECKERS AS POSSIBLE BY DIAGONAL JUMPS")
print("(AS IN STANDARD CHECKERS). USE THE NUMBERED BOARD TO")
print("INDICATE THE SQUARE YOU WISH TO JUMP FROM AND TO. ON")
print("THE BOARD PRINTED OUT ON EACH TURN '1' INDICATES A")
print("CHECKER AND '0' AN EMPTY SQUARE. WHEN YOU HAVE NO")
print("POSSIBLE JUMPS REMAINING, INPUT A '0' IN RESPONSE TO")
print("QUESTION 'JUMP FROM ?'")
print()
print("HERE IS THE NUMERICAL BOARD:")
print()
while True:
for j in range(1, 64, 8):
for i in range(j, j + 7):
print(i, end=(" " * (3 if i < 10 else 2)))
print(j + 7)
print()
print("AND HERE IS THE OPENING POSITION OF THE CHECKERS.")
print()
(jumps, left) = play_game()
print()
@@ -44,72 +46,83 @@ def main():
print("REMAINING ON THE BOARD.")
print()
if not(try_again()):
if not (try_again()):
break
print()
print("O.K. HOPE YOU HAD FUN!!")
def play_game():
# Initialize board
# Give more than 64 elements to accomodate 1-based indexing
board = [1]*70
for j in range(19,44,8):
for i in range(j,j+4):
board = [1] * 70
for j in range(19, 44, 8):
for i in range(j, j + 4):
board[i] = 0
jumps = 0
while True:
# print board
for j in range(1,64,8):
for i in range(j,j+7):
print(board[i], end=' ')
print(board[j+7])
for j in range(1, 64, 8):
for i in range(j, j + 7):
print(board[i], end=" ")
print(board[j + 7])
print()
while True:
print("JUMP FROM", end=' ')
print("JUMP FROM", end=" ")
f = input()
f = int(f)
if f == 0:
break
print("TO", end=' ')
print("TO", end=" ")
t = input()
t = int(t)
print()
# Check legality of move
f1 = ((f-1) // 8)
f1 = (f - 1) // 8
f2 = f - 8 * f1
t1 = ((t-1) // 8)
t1 = (t - 1) // 8
t2 = t - 8 * t1
if (f1 > 7 or t1 > 7 or f2 > 8 or t2 > 8 or abs(f1 - t1) != 2 or
abs(f2 - t2) != 2 or board[(t + f) // 2] == 0 or
board[f] == 0 or board[t] == 1):
if (
f1 > 7
or t1 > 7
or f2 > 8
or t2 > 8
or abs(f1 - t1) != 2
or abs(f2 - t2) != 2
or board[(t + f) // 2] == 0
or board[f] == 0
or board[t] == 1
):
print("ILLEGAL MOVE. TRY AGAIN...")
continue
break
if(f == 0):
if f == 0:
break
board[t] = 1
board[f] = 0
board[(t+f) // 2] = 0
board[(t + f) // 2] = 0
jumps = jumps + 1
left = 0
for i in range(1,64+1):
for i in range(1, 64 + 1):
left = left + board[i]
return (str(jumps), str(left))
def try_again():
print("TRY AGAIN", end=' ')
print("TRY AGAIN", end=" ")
answer = input()
if (answer.upper() == "YES"):
if answer.upper() == "YES":
return True
elif (answer.upper() == "NO"):
elif answer.upper() == "NO":
return False
print("PLEASE ANSWER 'YES' OR 'NO'.")
try_again()
if __name__ == '__main__':
if __name__ == "__main__":
main()