Spaces:
Configuration error
Configuration error
Upload stratego\web\components\move_input.py with huggingface_hub
Browse files
stratego//web//components//move_input.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Human move input widget - Beautifully styled move buttons"""
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from stratego.web.utils.validators import is_valid_move_string
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def render_move_input(game_controller):
|
| 7 |
+
"""Render beautiful clickable move buttons for human player"""
|
| 8 |
+
if not game_controller:
|
| 9 |
+
st.error("Game not initialized")
|
| 10 |
+
return None
|
| 11 |
+
|
| 12 |
+
if not game_controller.is_human_turn():
|
| 13 |
+
return None
|
| 14 |
+
|
| 15 |
+
legal_moves = game_controller.get_legal_moves()
|
| 16 |
+
|
| 17 |
+
if not legal_moves:
|
| 18 |
+
st.error("No legal moves available!")
|
| 19 |
+
return None
|
| 20 |
+
|
| 21 |
+
# Beautiful header with styling
|
| 22 |
+
st.markdown("""
|
| 23 |
+
<style>
|
| 24 |
+
.move-section {
|
| 25 |
+
background: linear-gradient(90deg, #2ecc71 0%, #27ae60 100%);
|
| 26 |
+
padding: 15px;
|
| 27 |
+
border-radius: 10px;
|
| 28 |
+
margin: 10px 0;
|
| 29 |
+
box-shadow: 0 4px 15px rgba(46, 204, 113, 0.3);
|
| 30 |
+
}
|
| 31 |
+
.move-title {
|
| 32 |
+
color: white;
|
| 33 |
+
font-size: 20px;
|
| 34 |
+
font-weight: bold;
|
| 35 |
+
margin: 0;
|
| 36 |
+
}
|
| 37 |
+
.move-buttons-container {
|
| 38 |
+
display: flex;
|
| 39 |
+
flex-wrap: wrap;
|
| 40 |
+
gap: 8px;
|
| 41 |
+
margin-top: 15px;
|
| 42 |
+
justify-content: flex-start;
|
| 43 |
+
}
|
| 44 |
+
</style>
|
| 45 |
+
<div class="move-section">
|
| 46 |
+
<p class="move-title">🎯 YOUR TURN - Click a Move Below</p>
|
| 47 |
+
</div>
|
| 48 |
+
""", unsafe_allow_html=True)
|
| 49 |
+
|
| 50 |
+
# Display moves as styled buttons
|
| 51 |
+
cols_per_row = 6
|
| 52 |
+
cols = st.columns(cols_per_row)
|
| 53 |
+
|
| 54 |
+
for idx, move in enumerate(legal_moves):
|
| 55 |
+
col_idx = idx % cols_per_row
|
| 56 |
+
with cols[col_idx]:
|
| 57 |
+
if st.button(
|
| 58 |
+
f"🎲 {move}",
|
| 59 |
+
use_container_width=True,
|
| 60 |
+
key=f"move_btn_{move}_{idx}",
|
| 61 |
+
help=f"Move from {move.split()[0]} to {move.split()[1]}"
|
| 62 |
+
):
|
| 63 |
+
return move.strip().upper()
|
| 64 |
+
|
| 65 |
+
return None
|