1 // Copyright 2020-2021 Ian Jackson and contributors to Otter
2 // SPDX-License-Identifier: AGPL-3.0-or-later
3 // There is NO WARRANTY.
11 fn move_money<PI:Idx>(&mut self,
12 a_pieces: &mut Pieces<PI>, piece: PI,
13 qty: i32, z: &str, pos: Pos) {
14 self.api_piece_op_single(PuSynch((&mut *a_pieces, piece)).id(), (
15 "multigrab", json!({ "n": qty, 'z': z })
18 self.api_piece(GH::Ungrab, PuSynch((&mut *a_pieces, piece)), pos)?;
24 fn multigrab(&mut self) {
25 let mut alice = self.connect_player(&self.alice)?;
26 let mut a_pieces = alice.pieces::<PIA>()?;
28 let bank = a_pieces.find_by_desc_glob("*400ƒ*");
30 let pile_pos = PosC::new(40,20);
31 let temp_pos = PosC::new(40,10);
33 alice.api_piece_op_single(PuSynch((&mut a_pieces, bank)).id(), (
34 "multigrab", json!({ "n": 50, 'z': "q000000000" })
36 alice.synchu(&mut a_pieces)?;
39 let bank = a_pieces.find_by_desc_glob("* 350ƒ*");
40 a_pieces[pile].assert_desc_contains(" 50ƒ");
42 alice.api_piece(GH::Ungrab, PuSynch((&mut a_pieces, pile)), pile_pos)?;
43 alice.synchu(&mut a_pieces)?;
45 alice.move_money(&mut a_pieces, bank, 13, "t000000000", temp_pos)?;
47 alice.synchu(&mut a_pieces)?;
48 let bank = a_pieces.find_by_desc_glob("* 337ƒ*");
49 a_pieces[moved].assert_desc_contains(" 13ƒ");
51 alice.api_piece(GH::With, PuSynch((&mut a_pieces, moved)), pile_pos)?;
52 alice.synchu(&mut a_pieces)?;
53 assert!(a_pieces[moved].info.is_null());
54 a_pieces[pile].assert_desc_contains(" 63ƒ");
56 // This saves us some complaints
63 fn occult(&mut self) {
64 self.clear_reset_to_demo()?;
66 let mut alice = self.connect_player(&self.alice)?;
67 let mut a_pieces = alice.pieces::<PIA>()?;
69 let mut bob = self.connect_player(&self.bob)?;
71 let hand = a_pieces.find_by_desc_glob(otter::hand::UNCLAIMED_HAND_DESC);
72 alice.api_piece(GH::With, PuSynch(&mut (&mut a_pieces, hand)),
73 ("k", json!({ "opname": "claim",
74 "wrc": WRC::Unpredictable })))?;
75 let hand_pos = a_pieces[hand].pos;
77 alice.synchu(&mut a_pieces)?;
79 let bank = a_pieces.find_by_desc_glob("*400ƒ*");
81 alice.move_money(&mut a_pieces, bank, 399, "u000000000", hand_pos)?;
82 alice.synchu(&mut a_pieces)?;
83 // old bank has 1f, current piece has 399
85 let div1_pos = (hand_pos + PosC::new(-30,-5))?;
86 alice.move_money(&mut a_pieces, bank, 99, "u010000000", div1_pos)?;
87 // in hand has 300, current piece, aside, has 99
89 alice.move_money(&mut a_pieces, bank, 9, "u020000000", hand_pos)?;
90 alice.synchu(&mut a_pieces)?;
91 // aside has 90, in hand has 9, original hand pos has 309
93 bob.synchx::<PIB,_>(None, None, |_session, gen, _k, v| v.tree_walk(|k,v| {
94 if let Some(s) = v.as_str() {
95 eprintln!("{} {:?} {:?}", gen, k, s);
106 fn tests(mut c: Ctx) {
107 test!(c, "multigrab", c.multigrab() ?);
108 test!(c, "occult", c.occult() ?);
113 tests(Ctx::setup()?)?;