mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-03-28 17:32:36 +01:00
Enhance Battleship
Summary This PR introduces several enhancements to the Battleship game module, focusing on player engagement, game feedback, and strategic depth. The changes include: Ping Command: Players can now use the hidden "p" command during their turn to scan a 3x3 area around their last move (or the board center if no moves have been made). The ping provides a hint about the presence of unsunk ships in the area, returning messages like "something lurking nearby" or "targets in the area!". To add suspense and realism, there is a 30% chance the ping will be disrupted, returning "Ping disrupted! No reading. Try again later." This feature does not consume a turn or affect game state, acting as a strategic hint tool. Game End Statistics: At the end of each game, players are now informed of the total number of shots fired and the elapsed time to victory. This provides a sense of accomplishment and encourages replayability as players try to improve their efficiency. Ammo Commentary: Every 25 and 50 shots, the game displays a humorous comment (e.g., "🥔25 fired!", "🥵50 rounds!") to keep players entertained and aware of their shot count. How Gameplay Is Improved Strategic Depth: The ping feature gives players a way to gather information and adjust their tactics, making gameplay more interactive and less reliant on random guessing. Player Engagement: Humorous ammo comments and end-of-game statistics add personality and feedback, making the experience more memorable and fun. Replay Value: By surfacing stats like shots fired and time taken, players are motivated to replay and beat their previous records. Fairness and Clarity: The ping command does not advance the turn or affect the game state, ensuring fairness and preventing accidental misuse. Testing & Compatibility All new features are integrated with both AI and P2P modes. Existing gameplay logic and win conditions remain unchanged. The ping command is robust against edge cases (e.g., no moves made, board edges). In summary: This PR makes Battleship more engaging, strategic, and fun, while preserving the integrity of the original game mechanics. Co-Authored-By: NillRudd <102033730+nillrudd@users.noreply.github.com>
This commit is contained in:
@@ -262,6 +262,62 @@ def playBattleship(message, nodeID, deviceID, session_id=None):
|
||||
msg = msg[2:].strip()
|
||||
msg = msg.replace(" ", "")
|
||||
|
||||
# --- Ping Command ---
|
||||
if msg == "p":
|
||||
import random
|
||||
# 30% chance to fail
|
||||
if random.random() < 0.3:
|
||||
return "I can hear a couple of 🦞lobsters dukin' it out down there..."
|
||||
# Determine center of ping
|
||||
if session.vs_ai:
|
||||
# Use last move if available, else center of board
|
||||
if session.shots_fired > 0:
|
||||
# Find last move coordinates from radar (most recent HIT or FIRE)
|
||||
radar = game.get_player_radar()
|
||||
found = False
|
||||
for i in range(SIZE):
|
||||
for j in range(SIZE):
|
||||
if radar[i][j] in (HIT, FIRE):
|
||||
center_y, center_x = i, j
|
||||
found = True
|
||||
if not found:
|
||||
center_y, center_x = SIZE // 2, SIZE // 2
|
||||
else:
|
||||
center_y, center_x = SIZE // 2, SIZE // 2
|
||||
# Scan 3x3 area on AI board for unsunk ship cells
|
||||
board = game.ai_board
|
||||
else:
|
||||
# For P2P, use player's radar and opponent's board
|
||||
if session.last_move:
|
||||
coord = session.last_move[1]
|
||||
center_y = ord(coord[0]) - ord('A')
|
||||
center_x = int(coord[1:]) - 1
|
||||
else:
|
||||
center_y, center_x = SIZE // 2, SIZE // 2
|
||||
# Scan 3x3 area on opponent's board
|
||||
if nodeID == session.player1_id:
|
||||
board = game.player2_board
|
||||
else:
|
||||
board = game.player1_board
|
||||
|
||||
min_y = max(0, center_y - 1)
|
||||
max_y = min(SIZE, center_y + 2)
|
||||
min_x = max(0, center_x - 1)
|
||||
max_x = min(SIZE, center_x + 2)
|
||||
ship_cells = set()
|
||||
for i in range(min_y, max_y):
|
||||
for j in range(min_x, max_x):
|
||||
cell = board[i][j]
|
||||
if cell.isdigit():
|
||||
ship_cells.add(cell)
|
||||
pong_count = len(ship_cells)
|
||||
if pong_count == 0:
|
||||
return "silence in the deep..."
|
||||
elif pong_count == 1:
|
||||
return "something lurking nearby."
|
||||
else:
|
||||
return f"targets in the area!"
|
||||
|
||||
x = y = None
|
||||
if "," in msg:
|
||||
parts = msg.split(",")
|
||||
|
||||
Reference in New Issue
Block a user