mirror of
https://github.com/LHY0125/Gobang-Game.git
synced 2026-06-29 08:55:53 +08:00
feat: 添加 env_logger 基础日志系统
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -133,7 +133,7 @@ fn now_string() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_leap_year(y: u64) -> bool {
|
fn is_leap_year(y: u64) -> bool {
|
||||||
(y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)
|
(y.is_multiple_of(4) && !y.is_multiple_of(100)) || y.is_multiple_of(400)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -15,3 +15,5 @@ tauri-plugin-opener = "2"
|
|||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
gobang-core = { path = "../core" }
|
gobang-core = { path = "../core" }
|
||||||
|
log = "0.4"
|
||||||
|
env_logger = "0.11"
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ impl Default for AppState {
|
|||||||
pub fn new_game(mode: GameMode, config: GameConfig, state: State<AppState>) -> Result<(), String> {
|
pub fn new_game(mode: GameMode, config: GameConfig, state: State<AppState>) -> Result<(), String> {
|
||||||
let is_vs_ai = mode == GameMode::VsAi;
|
let is_vs_ai = mode == GameMode::VsAi;
|
||||||
let board = Board::new(config.board_size);
|
let board = Board::new(config.board_size);
|
||||||
|
log::info!("新游戏: mode={:?}, board_size={}", mode, config.board_size);
|
||||||
*state.board.lock().map_err(|e| e.to_string())? = Some(board);
|
*state.board.lock().map_err(|e| e.to_string())? = Some(board);
|
||||||
*state.game_mode.lock().map_err(|e| e.to_string())? = mode;
|
*state.game_mode.lock().map_err(|e| e.to_string())? = mode;
|
||||||
*state.config.lock().map_err(|e| e.to_string())? = config.clone();
|
*state.config.lock().map_err(|e| e.to_string())? = config.clone();
|
||||||
@@ -82,6 +83,10 @@ pub fn place_piece(x: usize, y: usize, state: State<AppState>) -> Result<MoveRes
|
|||||||
*state.current_color.lock().map_err(|e| e.to_string())? = color.opponent();
|
*state.current_color.lock().map_err(|e| e.to_string())? = color.opponent();
|
||||||
*state.game_over.lock().map_err(|e| e.to_string())? = is_win;
|
*state.game_over.lock().map_err(|e| e.to_string())? = is_win;
|
||||||
|
|
||||||
|
if is_win {
|
||||||
|
log::info!("游戏结束: 胜者={:?}", color);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(MoveResult {
|
Ok(MoveResult {
|
||||||
position: pos,
|
position: pos,
|
||||||
is_win,
|
is_win,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use commands::AppState;
|
|||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
|
log::info!("Tauri 应用初始化完成");
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_opener::init())
|
.plugin(tauri_plugin_opener::init())
|
||||||
.manage(AppState::default())
|
.manage(AppState::default())
|
||||||
|
|||||||
@@ -2,5 +2,7 @@
|
|||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
env_logger::init();
|
||||||
|
log::info!("Gobang v2.0 启动");
|
||||||
gobang_gui::run()
|
gobang_gui::run()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user