ShubhanshuBansod commited on
Commit
84de733
·
verified ·
1 Parent(s): 7105520

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -2
app.py CHANGED
@@ -5,6 +5,7 @@ from connect_four_game import ConnectFour
5
  from minimax_ai import MinimaxAI
6
  from llm_explanation import MoveExplainer
7
  from report_generator import generate_match_report
 
8
 
9
  st.set_page_config(
10
  page_title="Connect Four AI Pro",
@@ -83,7 +84,7 @@ st.markdown('''
83
  margin-top: 1.5rem !important;
84
  }
85
 
86
- /* Game Board Container - Fixed to prevent overlap */
87
  .board-container {
88
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
89
  border-radius: 20px;
@@ -118,6 +119,36 @@ st.markdown('''
118
  position: static !important;
119
  }
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  /* Buttons - Gaming Style */
122
  .stButton button {
123
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
@@ -393,6 +424,25 @@ st.markdown('''
393
  </style>
394
  ''', unsafe_allow_html=True)
395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
  # Initialize Session State
397
  if 'game' not in st.session_state:
398
  st.session_state.game = ConnectFour()
@@ -416,6 +466,7 @@ if 'game' not in st.session_state:
416
  st.session_state.last_ai_algo_perf = None
417
  st.session_state.last_p1_algo_perf = None
418
  st.session_state.last_p2_algo_perf = None
 
419
 
420
  # Header
421
  col_title1, col_title2 = st.columns([3, 1])
@@ -542,6 +593,9 @@ if st.session_state.game_mode == "vs AI":
542
  board_str = st.session_state.game.board_to_string()
543
  st.markdown(f'<div class="board-container"><div class="board-display">{board_str}</div></div>', unsafe_allow_html=True)
544
 
 
 
 
545
  # Column Selection
546
  st.markdown("### 🎲 SELECT YOUR MOVE")
547
  cols = st.columns(7)
@@ -707,6 +761,9 @@ else: # Two Player Mode
707
  board_str = st.session_state.game.board_to_string()
708
  st.markdown(f'<div class="board-container"><div class="board-display">{board_str}</div></div>', unsafe_allow_html=True)
709
 
 
 
 
710
  # Current Player Indicator
711
  current_player_symbol = "🔴 RED" if st.session_state.current_player == 1 else "🟡 YELLOW"
712
  st.markdown(f'<div class="info-card"><h3 style="text-align: center;">Current Turn: {current_player_symbol}</h3></div>', unsafe_allow_html=True)
@@ -861,4 +918,4 @@ if st.session_state.game_over and st.session_state.move_history_detailed:
861
  file_name=f"connect_four_match_report_{timestamp}.txt",
862
  mime="text/plain",
863
  use_container_width=True
864
- )
 
5
  from minimax_ai import MinimaxAI
6
  from llm_explanation import MoveExplainer
7
  from report_generator import generate_match_report
8
+ import random
9
 
10
  st.set_page_config(
11
  page_title="Connect Four AI Pro",
 
84
  margin-top: 1.5rem !important;
85
  }
86
 
87
+ /* Game Board Container */
88
  .board-container {
89
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
90
  border-radius: 20px;
 
119
  position: static !important;
120
  }
121
 
122
+ /* Learning Insights Container */
123
+ .learning-insights {
124
+ background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
125
+ border-radius: 12px;
126
+ padding: 1rem;
127
+ margin-top: 1rem;
128
+ border-left: 4px solid #00D4FF;
129
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
130
+ }
131
+
132
+ .insight-title {
133
+ color: #00D4FF !important;
134
+ font-family: 'Orbitron', sans-serif !important;
135
+ font-weight: 700 !important;
136
+ font-size: 0.95rem !important;
137
+ text-shadow: 0 0 8px rgba(0, 212, 255, 0.5) !important;
138
+ margin-bottom: 0.8rem !important;
139
+ }
140
+
141
+ .insight-item {
142
+ background: rgba(0, 0, 0, 0.2);
143
+ border-left: 3px solid #00D4FF;
144
+ padding: 0.6rem 0.8rem;
145
+ margin: 0.5rem 0;
146
+ border-radius: 6px;
147
+ color: #E0E0E0 !important;
148
+ font-size: 0.9rem !important;
149
+ line-height: 1.4 !important;
150
+ }
151
+
152
  /* Buttons - Gaming Style */
153
  .stButton button {
154
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
 
424
  </style>
425
  ''', unsafe_allow_html=True)
426
 
427
+ # Academic insights from the learning guides
428
+ LEARNING_INSIGHTS = [
429
+ "💡 Minimax: Plans moves ahead like a chess master, evaluating all possibilities recursively",
430
+ "🚀 Alpha-Beta Pruning: Eliminates 60-70% of unnecessary branches, making deep search practical",
431
+ "🎮 Perfect Information: Connect Four has no hidden cards—AI can calculate optimal play",
432
+ "🌳 Search Depth: Each level deeper exponentially increases positions (7^d growth)",
433
+ "⚔️ Threat Detection: AI identifies winning opportunities AND blocks opponent threats",
434
+ "⏱️ Terminal States: When AI finds winning move immediately (depth 0), no deeper search needed",
435
+ "🔄 Recursion: Minimax calls itself to evaluate all game futures before deciding",
436
+ "📊 Big-O Notation: O(b^d) without pruning, O(b^d/2) with pruning—theory meets practice",
437
+ "🎯 Game Theory: Minimax chooses moves that maximize AI score, minimize opponent score",
438
+ "💾 State Management: Session state persists game across page refreshes—no data loss",
439
+ "🏆 Optimal Play: Depth 5 proves strong enough to block your best strategies",
440
+ "⏳ Time Trade-off: Deeper search = more thinking but slower response time",
441
+ "🤖 Heuristics: Evaluation function rates positions without exploring every possibility",
442
+ "🌐 DFS vs BFS: Game AI uses depth-first search (memory efficient) not breadth-first",
443
+ "📈 Exponential Growth: Why depth 8 takes 10x longer than depth 5",
444
+ ]
445
+
446
  # Initialize Session State
447
  if 'game' not in st.session_state:
448
  st.session_state.game = ConnectFour()
 
466
  st.session_state.last_ai_algo_perf = None
467
  st.session_state.last_p1_algo_perf = None
468
  st.session_state.last_p2_algo_perf = None
469
+ st.session_state.current_insight_index = 0
470
 
471
  # Header
472
  col_title1, col_title2 = st.columns([3, 1])
 
593
  board_str = st.session_state.game.board_to_string()
594
  st.markdown(f'<div class="board-container"><div class="board-display">{board_str}</div></div>', unsafe_allow_html=True)
595
 
596
+ # Learning Insights Section
597
+ st.markdown(f'<div class="learning-insights"><div class="insight-title">📚 QUICK INSIGHT</div><div class="insight-item">{random.choice(LEARNING_INSIGHTS)}</div></div>', unsafe_allow_html=True)
598
+
599
  # Column Selection
600
  st.markdown("### 🎲 SELECT YOUR MOVE")
601
  cols = st.columns(7)
 
761
  board_str = st.session_state.game.board_to_string()
762
  st.markdown(f'<div class="board-container"><div class="board-display">{board_str}</div></div>', unsafe_allow_html=True)
763
 
764
+ # Learning Insights Section
765
+ st.markdown(f'<div class="learning-insights"><div class="insight-title">📚 QUICK INSIGHT</div><div class="insight-item">{random.choice(LEARNING_INSIGHTS)}</div></div>', unsafe_allow_html=True)
766
+
767
  # Current Player Indicator
768
  current_player_symbol = "🔴 RED" if st.session_state.current_player == 1 else "🟡 YELLOW"
769
  st.markdown(f'<div class="info-card"><h3 style="text-align: center;">Current Turn: {current_player_symbol}</h3></div>', unsafe_allow_html=True)
 
918
  file_name=f"connect_four_match_report_{timestamp}.txt",
919
  mime="text/plain",
920
  use_container_width=True
921
+ )