use rand;
use rand::Rng;
use std::io;
fn main() {
let choices = ["石头", "剪刀", "布"];
let computer_choice = rand::thread_rng().gen_range(0..3);
println!("欢迎来到猜拳游戏!");
println!("请出拳:");
println!("1. 石头");
println!("2. 剪刀");
println!("3. 布");
let mut player_choice = String::new();
io::stdin().read_line(&mut player_choice).expect("无法读取输入。");
let player_choice: usize = player_choice.trim().parse().expect("请输入有效数字。");
println!("你的选择:{}", choices[player_choice - 1]);
println!("电脑的选择:{}", choices[computer_choice]);
if player_choice == computer_choice {
println!("平局!");
} else if (player_choice == 1 && computer_choice == 2)
|| (player_choice == 2 && computer_choice == 3)
|| (player_choice == 3 && computer_choice == 1)
{
println!("你赢了!");
} else {
println!("你输了!");
}
}