use rand::Rng;
use rand::prelude::ThreadRng;
use std::cmp::Ordering;

#[derive(PartialEq, Copy, Clone, Debug)]
enum Guess {
    石头,
    剪刀,
    ,
}

impl PartialOrd for Guess {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        match (self, other) {
            (Guess::石头, Guess::剪刀) | (Guess::剪刀, Guess::) | (Guess::, Guess::石头) => {
                Some(Ordering::Greater)
            }

            (Guess::石头, Guess::) | (Guess::剪刀, Guess::石头) | (Guess::, Guess::剪刀) => {
                Some(Ordering::Less)
            }
            (Guess::石头, Guess::石头) | (Guess::剪刀, Guess::剪刀) | (Guess::, Guess::) => {
                Some(Ordering::Equal)
            }
        }
    }
}

fn gen_guess(last: Option<Guess>, rand: &mut ThreadRng) -> Guess {
    use crate::Guess::{剪刀, , 石头};

    match last {
        None => {
            let all = vec![剪刀, 石头, ];
            rand_one(all, rand)
        }
        Some(guess) => match guess {
            石头 => {
                let all = vec![剪刀, ];
                rand_one(all, rand)
            }
            剪刀 => {
                let all = vec![石头, ];
                rand_one(all, rand)
            }
             => {
                let all = vec![剪刀, 石头];
                rand_one(all, rand)
            }
        },
    }
}

fn rand_one(all: Vec<Guess>, rand: &mut ThreadRng) -> Guess {
    let idx = rand.random::<u32>() as usize % all.len();
    let item = all[idx];
    item
}

fn go() {
    let mut rand = rand::rng();

    let mut last = None;
    let count = 1_000_000;
    let mut a_win = 0;
    let mut b_win = 0;
    println!("A角色随机, B根据A上次出手结果在剩下的里面选择");
    for i in 0..count {
        // println!("last: {last:?}");
        let a = gen_guess(None, &mut rand);
        let b = gen_guess(last, &mut rand);

        if a > b {
            a_win += 1;
        } else if b > a {
            b_win += 1;
        }

        last = Some(a);
    }

    println!("结果: A win: {}, {}, B win: {}, {}, Total: {}", a_win, a_win as f64/count as f64, b_win, b_win as f64/count as f64, count);
}

fn main() {
    println!("Hello, world!");
    go();
}

结果

A角色随机, B根据A上次出手结果在剩下的里面选择 结果: A win: 333115, 0.333115, B win: 332966, 0.332966, Total: 1000000