Spaces:
Sleeping
Sleeping
File size: 2,303 Bytes
9f1dfa7 0f9bb91 9f1dfa7 803c131 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
---
title: Battleship AI
emoji: 🏴☠️
colorFrom: purple
colorTo: purple
sdk: streamlit
sdk_version: 1.40.2
app_file: app.py
pinned: false
license: apache-2.0
---
# Battleship Game
This is a Streamlit-based implementation of the classic Battleship game, featuring a player versus an AI opponent powered by AWS Bedrock's Claude model.
## Features
- Interactive game board using Streamlit components
- AI opponent using AWS Bedrock's Claude model
- Game state persistence using MongoDB Atlas
- Randomized ship placement
- Turn-based gameplay
## Prerequisites
- Python 3.7+
- Streamlit
- pymongo
- boto3
- AWS account with Bedrock Claude 3.5 access on `US-EAST-1`.
- MongoDB Atlas account with your IP in the accesslist permission.
## Installation
1. Clone the repository:
```
cd atlas-ai-battleship-game
```
2. Install the required packages:
```
pip install -r requirements.txt
```
3. Set up environment variables:
- `MONGODB_ATLAS_URI`: Your MongoDB Atlas connection string
- `AWS_ACCESS_KEY`: Your AWS access key
- `AWS_SECRET_KEY`: Your AWS secret key
## Running the Game
To start the game, run:
```
streamlit run battleship-game.py
```
## How to Play
1. The game starts with ships randomly placed on both the player's and opponent's boards.
2. Click on the ocean emoji (🌊) on the attack board to make your move.
3. The AI opponent (Claude) will make its move automatically.
4. The game continues until all ships of one player are sunk.
5. You can mark the ships you have sank.
## Code Structure
- `main()`: The main function that sets up the Streamlit UI and game flow.
- `initialize_game()`: Initializes the game state and database entries.
- `render_board()`: Renders the game boards using Streamlit components.
- `attack()`: Processes a player's attack.
- `opponent_turn()`: Handles the AI opponent's turn using Claude.
- `get_bedrock_claude_move()`: Interacts with AWS Bedrock to get Claude's next move.
- `update_database()`: Updates the game state in the MongoDB database.
## Future Improvements
- Implement a more sophisticated AI strategy
- Add sound effects and animations
- Create a multiplayer mode
- Improve the UI/UX with more detailed ship information and game statistics
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
|