added attribution

This commit is contained in:
cqql 2024-10-19 12:14:08 +02:00
parent 016b3aa6cf
commit 07df42521a

View file

@ -11,9 +11,15 @@ pub struct GameServer {}
impl GameServer {
pub async fn handle(socket: &mut TcpStream) -> Result<(), String> {
send_text("Connect 4\nChoose your difficulty [1-9]: ", socket).await?;
send_text(
("Game AI designed by https://balkarjun.github.io\n".to_string()
+ "Game interface coded by https://cqql.site\n\n"
+ "Connect 4\nChoose your difficulty [1-9]: ").as_str(),
socket,
)
.await?;
let depth = get_one_char(b"123456789", socket).await? - b'0';
let depth = get_one_char(b"123456789", socket).await? - b'0' + 2;
println!("Difficulty: {depth}");
@ -22,14 +28,14 @@ impl GameServer {
let mut end_score: i64 = -1;
while end_score == -1 {
match board.counter % 2 == 0 {
true => {
send_text(format!("Move {}:\n", board.counter).as_str(), socket).await?;
send_text(board.to_string().as_str(), socket).await?;
send_text("Choose column: ", socket).await?;
let mut player_move = get_one_char(b"1234567", socket).await? - b'0';
send_text("[AI thinking]\n", socket).await?;
while !board.move_is_valid((player_move - 1).into()) {
send_text("Illegal move.\nChoose column: ", socket).await?;
player_move = get_one_char(b"1234567", socket).await? - b'0';
@ -38,7 +44,7 @@ impl GameServer {
board.make_move((player_move - 1).into());
end_score = board.end_state_reached();
send_text("\n", socket).await?;
},
}
false => {
let best_move = connect4::get_minimax_move(&mut board, depth.into());
@ -49,15 +55,17 @@ impl GameServer {
}
if end_score == 0 {
send_text( "It's a Tie\n\n", socket).await?;
send_text("It's a Tie\n\n", socket).await?;
} else if end_score > 0 {
send_text("White (●) Won!\n\n", socket).await?;
} else {
send_text("Black (○) Won!\n\n", socket).await?;
}
send_text(&board.to_string(), socket).await?;
send_text("Reconnect to play again\n", socket).await?;
Ok(())
}
}