Skip to content

Commit 1c507bb

Browse files
committed
Make the match more interesting by making hop1zuo1/tam less frequent
1 parent 833c238 commit 1c507bb

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cetkaik_random_play"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
authors = ["sozysozbot <sozysozbot@gmail.com>"]
55
edition = "2018"
66
license = "MIT"

src/lib.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ mod tests {
88

99
use cetkaik_full_state_transition::*;
1010

11+
fn deincentivize_tam_move(candidates: &[message::PureMove]) -> message::PureMove {
12+
use rand::seq::SliceRandom;
13+
use rand::Rng;
14+
let mut rng = rand::thread_rng();
15+
loop {
16+
let cand = candidates.choose(&mut rng).unwrap();
17+
18+
if (rng.gen::<f64>() < 0.05_f64)
19+
== matches!(cand,
20+
message::PureMove::NormalMove(
21+
message::NormalMove::TamMoveNoStep{..}
22+
) | message::PureMove::NormalMove(
23+
message::NormalMove::TamMoveStepsDuringFormer{..}
24+
) | message::PureMove::NormalMove(
25+
message::NormalMove::TamMoveStepsDuringLatter{..}
26+
))
27+
{
28+
return cand.to_owned();
29+
}
30+
}
31+
}
32+
1133
#[must_use]
1234
pub fn yield_random_next(current_state: &state::A, config: Config) -> Option<state::A> {
1335
use rand::seq::SliceRandom;
@@ -16,15 +38,15 @@ pub fn yield_random_next(current_state: &state::A, config: Config) -> Option<sta
1638
let (hop1zuo1_candidates, candidates) = current_state.get_candidates(config);
1739
let candidate = match (&hop1zuo1_candidates[..], &candidates[..]) {
1840
([], []) => return None, // stuck; yield no more
19-
([], candidates) => candidates.choose(&mut rng).unwrap(),
20-
(hop1zuo1_candidates, []) => hop1zuo1_candidates.choose(&mut rng).unwrap(),
41+
([], candidates) => deincentivize_tam_move(&candidates),
42+
(hop1zuo1_candidates, []) => hop1zuo1_candidates.choose(&mut rng).unwrap().to_owned(),
2143
(hop1zuo1_candidates, candidates) => {
22-
if rng.gen::<f64>() < 0.1_f64 {
44+
if rng.gen::<f64>() < 0.01_f64 {
2345
// choose randomly from hop1zuo1_candidates
24-
hop1zuo1_candidates.choose(&mut rng).unwrap()
46+
hop1zuo1_candidates.choose(&mut rng).unwrap().to_owned()
2547
} else {
2648
// choose randomly from candidates
27-
candidates.choose(&mut rng).unwrap()
49+
deincentivize_tam_move(&candidates)
2850
}
2951
}
3052
}
@@ -39,7 +61,9 @@ pub fn yield_random_next(current_state: &state::A, config: Config) -> Option<sta
3961

4062
let c_candidates = c.get_candidates(config);
4163

42-
let c_msg = *c_candidates.choose(&mut rng).expect("This cannot fail, because it is always legal to cancel");
64+
let c_msg = *c_candidates
65+
.choose(&mut rng)
66+
.expect("This cannot fail, because it is always legal to cancel");
4367

4468
let (hand_not_resolved, maybe_ciurl) = apply_after_half_acceptance(&c, c_msg, config)
4569
.map_err(|e| format!("Internal error in yield_random_next: {}", e))

0 commit comments

Comments
 (0)