diff --git a/src/systems/actions.cairo b/src/systems/actions.cairo index ab6ff7a..45f3a59 100644 --- a/src/systems/actions.cairo +++ b/src/systems/actions.cairo @@ -478,8 +478,8 @@ pub mod actions { game_player.dice_rolled = steps; - if game_player.position > 40 { - game_player.position = ((game_player.position - 1) % 40) + 1; + if game_player.position >= 40 { + game_player.position %= 40; game_player.balance += 200; } @@ -839,14 +839,14 @@ pub mod actions { let property = self.get_property(player.position, game.id); assert(property.property_type == PropertyType::Chance, 'not on chance'); if card == "Advance to Go (Collect $200)" { - player.position = 1; + player.position = 0; player.balance += 200; - } else if card == "Advance to Illinois Avenue - If you pass Go, collect $200" { + } else if card == "Advance to MakerDAO Avenue - If you pass Go, collect $200" { if player.position > 24 { // suppose Illinois is tile 24 player.balance += 200; } player.position = 24; - } else if card == "Advance to St. Charles Place - If you pass Go, collect $200" { + } else if card == "Advance to Arbitrium Avenue - If you pass Go, collect $200" { if player.position > 11 { player.balance += 200; } @@ -868,15 +868,25 @@ pub mod actions { let rail_pos = self.find_nearest(player.position, pos); player.position = rail_pos; let rail = self.get_property(rail_pos, game.clone().id); - self.pay_rent(rail); - self.pay_rent(rail); + let mut rail_owner: GamePlayer = self.retrieve_game_player(rail.owner, game.id); + let railroads = self.count_owner_railroads(property.owner, property.game_id); + let utilities = self.count_owner_utilities(property.owner, property.game_id); + let mut rent_amount = rail + .get_rent_amount(railroads, utilities, player.dice_rolled.into()); + if (rail.owner == get_contract_address()) { + rent_amount = 0; + } + player.balance -= rent_amount; + rail_owner.balance += rent_amount; + + world.write_model(@rail_owner); } else if card == "Bank pays you dividend of $50" { player.balance += 50; } else if card == "Get out of Jail Free" { player.chance_jail_card = true; } else if card == "Go Back 3 Spaces" { if player.position < 4 { - player.position = 40 - (4 - player.position); + player.position = 39 - (4 - player.position); } else { player.position -= 3; } @@ -890,12 +900,12 @@ pub mod actions { player.balance -= cost.into(); } else if card == "Pay poor tax of $15" { player.balance -= 15; - } else if card == "Take a trip to Reading Railroad" { - if player.position > 6 { + } else if card == "Take a trip to IPFS Railroad" { + if player.position > 5 { player.balance += 200; } - player.position = 6; // reading railroad - } else if card == "Take a walk on the Boardwalk" { + player.position = 5; // reading railroad + } else if card == "Take a walk on the Bitcoin Lane" { player.position = 39; } else if card == "Speeding fine $200" { player.balance -= 200; @@ -984,8 +994,8 @@ pub mod actions { let mut deck: Array = array![]; deck.append("Advance to Go (Collect $200)"); - deck.append("Advance to Illinois Avenue - If you pass Go, collect $200"); - deck.append("Advance to St. Charles Place - If you pass Go, collect $200"); + deck.append("Advance to MakerDAO Avenue - If you pass Go, collect $200"); + deck.append("Advance to Arbitrium Avenue - If you pass Go, collect $200"); deck.append("Advance token to nearest Utility. Pay 10x dice."); deck.append("Advance token to nearest Railroad. Pay 2x rent."); deck.append("Bank pays you dividend of $50"); @@ -995,7 +1005,7 @@ pub mod actions { deck.append("Make general repairs - $25 house, $100 hotel"); deck.append("Pay poor tax of $15"); deck.append("Take a trip to Reading Railroad"); - deck.append("Take a walk on the Boardwalk"); + deck.append("Take a walk on the Bitcoin Lane"); deck.append("Speeding fine $200"); deck.append("Building loan matures - collect $150"); @@ -1130,32 +1140,6 @@ pub mod actions { } - fn generate_community_chest_deck(ref self: ContractState) -> Array { - let mut deck: Array = array![]; - - deck.append("Advance to Go (Collect $200)"); - deck.append("Bank error in your favor - Collect $200"); - deck.append("Doctor fee - Pay $50"); - deck.append("From sale of stock - collect $50"); - deck.append("Get Out of Jail Free"); - deck.append("Go to Jail"); - deck.append("Grand Opera Night - collect $50 from every player"); - deck.append("Holiday Fund matures - Receive $100"); - deck.append("Income tax refund - Collect $20"); - deck.append("Life insurance matures - Collect $100"); - deck.append("Pay hospital fees of $100"); - deck.append("Pay school fees of $150"); - deck.append("Receive $25 consultancy fee"); - deck.append("Street repairs - $40 per house, $115 per hotel"); - deck.append("Won second prize in beauty contest - Collect $10"); - deck.append("You inherit $100"); - - // self.shuffle_array(deck); - - deck - } - - fn generate_board_tiles(ref self: ContractState, game_id: u256) { let mut world = self.world_default(); let contract_address = get_contract_address(); @@ -1163,7 +1147,7 @@ pub mod actions { self .generate_properties( - 1, + 0, game_id, 'Go', 0, @@ -1181,7 +1165,7 @@ pub mod actions { ); self .generate_properties( - 2, + 1, game_id, 'Axone Avenue', 60, @@ -1199,7 +1183,7 @@ pub mod actions { ); self .generate_properties( - 3, + 2, game_id, 'Community Chest', 0, @@ -1217,7 +1201,7 @@ pub mod actions { ); self .generate_properties( - 4, + 3, game_id, 'Onlydust Avenue', 60, @@ -1233,6 +1217,24 @@ pub mod actions { 1, bank.address, ); + self + .generate_properties( + 4, + game_id, + 'Luxury Tax', + 100, + PropertyType::Tax, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + false, + 0, + bank.address, + ); self .generate_properties( 5, @@ -1251,6 +1253,7 @@ pub mod actions { 0, bank.address, ); + self .generate_properties( 6, @@ -1323,6 +1326,7 @@ pub mod actions { 2, bank.address, ); + self .generate_properties( 10, @@ -1341,7 +1345,6 @@ pub mod actions { 0, bank.address, ); - self .generate_properties( 11, @@ -1400,18 +1403,18 @@ pub mod actions { .generate_properties( 14, game_id, - 'Community Chest', - 0, - PropertyType::CommunityChest, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 'Base Avenue', + 160, + PropertyType::Property, + 12, + 60, + 180, + 500, + 700, + 900, + 100, false, - 0, + 3, bank.address, ); self @@ -1432,31 +1435,32 @@ pub mod actions { 0, bank.address, ); + self .generate_properties( 16, game_id, - 'Base Avenue', - 160, + 'Near Lane', + 200, PropertyType::Property, - 12, - 60, - 180, - 500, - 700, - 900, + 14, + 70, + 200, + 550, + 750, + 950, 100, false, - 3, + 4, bank.address, ); self .generate_properties( 17, game_id, - 'Chance', + 'Community Chest', 0, - PropertyType::Chance, + PropertyType::CommunityChest, 0, 0, 0, @@ -1504,6 +1508,7 @@ pub mod actions { 4, bank.address, ); + self .generate_properties( 20, @@ -1522,32 +1527,31 @@ pub mod actions { 0, bank.address, ); - self .generate_properties( 21, game_id, - 'Near Lane', - 200, - PropertyType::Property, - 16, - 80, + 'Dune Lane', 220, - 600, - 800, - 1000, - 100, + PropertyType::Property, + 18, + 90, + 250, + 700, + 875, + 1050, + 150, false, - 4, + 5, bank.address, ); self .generate_properties( 22, game_id, - 'Community Chest', + 'Chance', 0, - PropertyType::CommunityChest, + PropertyType::Chance, 0, 0, 0, @@ -1582,14 +1586,14 @@ pub mod actions { 24, game_id, 'MakerDAO Avenue', - 220, + 240, PropertyType::Property, - 18, - 90, - 250, - 700, - 875, - 1050, + 20, + 100, + 300, + 750, + 925, + 1100, 150, false, 5, @@ -1613,22 +1617,23 @@ pub mod actions { 0, bank.address, ); + self .generate_properties( 26, game_id, 'Aave Avenue', - 240, + 260, PropertyType::Property, - 20, - 100, - 300, - 750, - 925, - 1100, + 22, + 110, + 330, + 800, + 975, + 1150, 150, false, - 5, + 6, bank.address, ); self @@ -1671,20 +1676,21 @@ pub mod actions { .generate_properties( 29, game_id, - 'Chance', - 0, - PropertyType::Chance, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 'Rootstock Lane', + 260, + PropertyType::Property, + 22, + 110, + 330, + 800, + 975, + 1150, + 150, false, - 0, + 6, bank.address, ); + self .generate_properties( 30, @@ -1703,23 +1709,22 @@ pub mod actions { 0, bank.address, ); - self .generate_properties( 31, game_id, 'Rootstock Lane', - 260, + 300, PropertyType::Property, - 22, - 110, - 330, - 800, - 975, - 1150, - 150, + 26, + 130, + 390, + 900, + 1100, + 1275, + 200, false, - 6, + 7, bank.address, ); self @@ -1729,15 +1734,15 @@ pub mod actions { 'Ark Lane', 280, PropertyType::Property, - 24, - 120, - 360, - 850, - 1025, - 1200, - 150, + 26, + 130, + 390, + 900, + 1100, + 1275, + 200, false, - 6, + 7, bank.address, ); self @@ -1794,6 +1799,7 @@ pub mod actions { 0, bank.address, ); + self .generate_properties( 36, @@ -1817,17 +1823,17 @@ pub mod actions { 37, game_id, 'Solana Drive', - 300, + 350, PropertyType::Property, - 26, - 130, - 390, - 900, + 35, + 175, + 500, 1100, - 1275, + 1300, + 1500, 200, false, - 7, + 8, bank.address, ); self @@ -1853,24 +1859,6 @@ pub mod actions { 39, game_id, 'Ethereum Avenue', - 320, - PropertyType::Property, - 28, - 150, - 450, - 1000, - 1200, - 1400, - 200, - false, - 7, - bank.address, - ); - self - .generate_properties( - 40, - game_id, - 'Bitcoin Lane', 400, PropertyType::Property, 50, @@ -1887,6 +1875,31 @@ pub mod actions { } + fn generate_community_chest_deck(ref self: ContractState) -> Array { + let mut deck: Array = array![]; + + deck.append("Advance to Go (Collect $200)"); + deck.append("Bank error in your favor - Collect $200"); + deck.append("Doctor fee - Pay $50"); + deck.append("From sale of stock - collect $50"); + deck.append("Get Out of Jail Free"); + deck.append("Go to Jail"); + deck.append("Grand Opera Night - collect $50 from every player"); + deck.append("Holiday Fund matures - Receive $100"); + deck.append("Income tax refund - Collect $20"); + deck.append("Life insurance matures - Collect $100"); + deck.append("Pay hospital fees of $100"); + deck.append("Pay school fees of $150"); + deck.append("Receive $25 consultancy fee"); + deck.append("Street repairs - $40 per house, $115 per hotel"); + deck.append("Won second prize in beauty contest - Collect $10"); + deck.append("You inherit $100"); + + // self.shuffle_array(deck); + + deck + } + fn try_join_symbol( ref self: ContractState, mut game: Game, diff --git a/src/tests/test_world.cairo b/src/tests/test_world.cairo index 3558b99..222511c 100644 --- a/src/tests/test_world.cairo +++ b/src/tests/test_world.cairo @@ -378,7 +378,7 @@ mod tests { assert(started, 'Game start fail'); let game_p = actions_system.retrieve_game(1); - println!("Game players :{}", game_p.game_players.len()); + testing::set_contract_address(caller_1); actions_system.move_player(1, 5); @@ -440,7 +440,7 @@ mod tests { assert(started, 'Game start fail'); let game_p = actions_system.retrieve_game(1); - println!("Game players :{}", game_p.game_players.len()); + testing::set_contract_address(caller_1); actions_system.move_player(1, 5); let _property = actions_system.get_property(39, 1); @@ -493,7 +493,6 @@ mod tests { assert(started, 'Game start fail'); let game_p = actions_system.retrieve_game(1); - println!("Game players :{}", game_p.game_players.len()); testing::set_contract_address(caller_1); actions_system.move_player(1, 5); @@ -915,8 +914,8 @@ mod tests { assert(started, 'Game start fail'); testing::set_contract_address(caller_1); - actions_system.move_player(1, 2); - let mut property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let mut property = actions_system.get_property(1, 1); actions_system.buy_property(property); testing::set_contract_address(caller_2); @@ -937,7 +936,7 @@ mod tests { testing::set_contract_address(caller_1); actions_system.move_player(1, 2); - property = actions_system.get_property(4, 1); + property = actions_system.get_property(3, 1); actions_system.buy_property(property); testing::set_contract_address(caller_2); @@ -957,37 +956,37 @@ mod tests { actions_system.finish_turn(game); testing::set_contract_address(caller_1); - property = actions_system.get_property(4, 1); + property = actions_system.get_property(3, 1); actions_system.buy_house_or_hotel(property); - property = actions_system.get_property(2, 1); + property = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); - property = actions_system.get_property(4, 1); + property = actions_system.get_property(3, 1); actions_system.buy_house_or_hotel(property); - property = actions_system.get_property(2, 1); + property = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); - property = actions_system.get_property(4, 1); + property = actions_system.get_property(3, 1); actions_system.buy_house_or_hotel(property); - property = actions_system.get_property(2, 1); + property = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); - property = actions_system.get_property(4, 1); + property = actions_system.get_property(3, 1); actions_system.buy_house_or_hotel(property); - property = actions_system.get_property(2, 1); + property = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); - property = actions_system.get_property(4, 1); + property = actions_system.get_property(3, 1); actions_system.buy_house_or_hotel(property); - property = actions_system.get_property(2, 1); + property = actions_system.get_property(1, 1); let success = actions_system.buy_house_or_hotel(property); assert(success, 'house failed'); - property = actions_system.get_property(4, 1); + property = actions_system.get_property(3, 1); assert(property.development == 5, 'dev correct'); let aji = actions_system.retrieve_game_player(caller_1, 1); @@ -1028,26 +1027,26 @@ mod tests { // Player 1 buys property at position 4 testing::set_contract_address(caller_1); - actions_system.move_player(1, 2); - let mut property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let mut property = actions_system.get_property(1, 1); actions_system.buy_property(property); // Player 2 lands and pays rent testing::set_contract_address(caller_2); - actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let landed_property = actions_system.get_property(1, 1); actions_system.pay_rent(landed_property); // Player 1 buys property at position 4 testing::set_contract_address(caller_1); actions_system.move_player(1, 2); - let mut property = actions_system.get_property(4, 1); + let mut property = actions_system.get_property(3, 1); actions_system.buy_property(property); // Player 2 lands and pays rent testing::set_contract_address(caller_2); actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); let aji = actions_system.retrieve_game_player(caller_1, 1); @@ -1089,31 +1088,31 @@ mod tests { // SITE ONLY testing::set_contract_address(caller_1); - actions_system.move_player(1, 2); - let mut property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let mut property = actions_system.get_property(1, 1); actions_system.buy_property(property); // Player 2 lands and pays rent testing::set_contract_address(caller_2); - actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let landed_property = actions_system.get_property(1, 1); actions_system.pay_rent(landed_property); testing::set_contract_address(caller_1); actions_system.move_player(1, 2); - let mut property = actions_system.get_property(4, 1); + let mut property = actions_system.get_property(3, 1); actions_system.buy_property(property); testing::set_contract_address(caller_2); actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); // ONE HOUSE testing::set_contract_address(caller_1); actions_system.move_player(1, 40); - let mut property = actions_system.get_property(4, 1); - let mut property1 = actions_system.get_property(2, 1); + let mut property = actions_system.get_property(3, 1); + let mut property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); @@ -1122,13 +1121,14 @@ mod tests { testing::set_contract_address(caller_2); actions_system.move_player(1, 40); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); let aji = actions_system.retrieve_game_player(caller_1, 1); let collins = actions_system.retrieve_game_player(caller_2, 1); + assert(aji.balance == 1506, 'Aji bal error'); assert(collins.balance == 1674, 'Collins bal error'); assert(property.development == 1, 'Property dev error'); @@ -1169,37 +1169,37 @@ mod tests { // SITE ONLY testing::set_contract_address(caller_1); - actions_system.move_player(1, 2); - let mut property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let mut property = actions_system.get_property(1, 1); actions_system.buy_property(property); // Player 2 lands and pays rent testing::set_contract_address(caller_2); - actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let landed_property = actions_system.get_property(1, 1); actions_system.pay_rent(landed_property); testing::set_contract_address(caller_1); actions_system.move_player(1, 2); - let mut property = actions_system.get_property(4, 1); + let mut property = actions_system.get_property(3, 1); actions_system.buy_property(property); testing::set_contract_address(caller_2); actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); // ONE HOUSE testing::set_contract_address(caller_1); actions_system.move_player(1, 40); - let mut property = actions_system.get_property(4, 1); - let mut property1 = actions_system.get_property(2, 1); + let mut property = actions_system.get_property(3, 1); + let mut property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); @@ -1209,11 +1209,11 @@ mod tests { testing::set_contract_address(caller_2); actions_system.move_player(1, 40); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); let aji = actions_system.retrieve_game_player(caller_1, 1); let collins = actions_system.retrieve_game_player(caller_2, 1); @@ -1257,42 +1257,42 @@ mod tests { // SITE ONLY testing::set_contract_address(caller_1); - actions_system.move_player(1, 2); - let mut property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let mut property = actions_system.get_property(1, 1); actions_system.buy_property(property); // Player 2 lands and pays rent testing::set_contract_address(caller_2); - actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let landed_property = actions_system.get_property(1, 1); actions_system.pay_rent(landed_property); testing::set_contract_address(caller_1); actions_system.move_player(1, 2); - let mut property = actions_system.get_property(4, 1); + let mut property = actions_system.get_property(3, 1); actions_system.buy_property(property); testing::set_contract_address(caller_2); actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); // THREE HOUSES testing::set_contract_address(caller_1); actions_system.move_player(1, 40); - let mut property = actions_system.get_property(4, 1); - let mut property1 = actions_system.get_property(2, 1); + let mut property = actions_system.get_property(3, 1); + let mut property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); @@ -1302,11 +1302,11 @@ mod tests { testing::set_contract_address(caller_2); actions_system.move_player(1, 40); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); let aji = actions_system.retrieve_game_player(caller_1, 1); let collins = actions_system.retrieve_game_player(caller_2, 1); @@ -1351,48 +1351,48 @@ mod tests { // SITE ONLY testing::set_contract_address(caller_1); - actions_system.move_player(1, 2); - let mut property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let mut property = actions_system.get_property(1, 1); actions_system.buy_property(property); // Player 2 lands and pays rent testing::set_contract_address(caller_2); - actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let landed_property = actions_system.get_property(1, 1); actions_system.pay_rent(landed_property); testing::set_contract_address(caller_1); actions_system.move_player(1, 2); - let mut property = actions_system.get_property(4, 1); + let mut property = actions_system.get_property(3, 1); actions_system.buy_property(property); testing::set_contract_address(caller_2); actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); // Four HOUSES testing::set_contract_address(caller_1); actions_system.move_player(1, 40); - let mut property = actions_system.get_property(4, 1); - let mut property1 = actions_system.get_property(2, 1); + let mut property = actions_system.get_property(1, 1); + let mut property1 = actions_system.get_property(3, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); @@ -1402,11 +1402,11 @@ mod tests { testing::set_contract_address(caller_2); actions_system.move_player(1, 40); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); let aji = actions_system.retrieve_game_player(caller_1, 1); let collins = actions_system.retrieve_game_player(caller_2, 1); @@ -1450,54 +1450,54 @@ mod tests { // SITE ONLY testing::set_contract_address(caller_1); - actions_system.move_player(1, 2); - let mut property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let mut property = actions_system.get_property(1, 1); actions_system.buy_property(property); // Player 2 lands and pays rent testing::set_contract_address(caller_2); - actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let landed_property = actions_system.get_property(1, 1); actions_system.pay_rent(landed_property); testing::set_contract_address(caller_1); actions_system.move_player(1, 2); - let mut property = actions_system.get_property(4, 1); + let mut property = actions_system.get_property(3, 1); actions_system.buy_property(property); testing::set_contract_address(caller_2); actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); // Four HOUSES testing::set_contract_address(caller_1); actions_system.move_player(1, 40); - let mut property = actions_system.get_property(4, 1); - let mut property1 = actions_system.get_property(2, 1); + let mut property = actions_system.get_property(3, 1); + let mut property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); @@ -1507,11 +1507,11 @@ mod tests { testing::set_contract_address(caller_2); actions_system.move_player(1, 40); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); let aji = actions_system.retrieve_game_player(caller_1, 1); let collins = actions_system.retrieve_game_player(caller_2, 1); @@ -1556,19 +1556,19 @@ mod tests { // SITE ONLY testing::set_contract_address(caller_1); - actions_system.move_player(1, 2); - let mut property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let mut property = actions_system.get_property(1, 1); actions_system.buy_property(property); // Player 2 lands and pays rent testing::set_contract_address(caller_2); - actions_system.move_player(1, 2); - let landed_property = actions_system.get_property(2, 1); + actions_system.move_player(1, 1); + let landed_property = actions_system.get_property(1, 1); actions_system.pay_rent(landed_property); testing::set_contract_address(caller_1); actions_system.move_player(1, 2); - let mut property = actions_system.get_property(4, 1); + let mut property = actions_system.get_property(3, 1); actions_system.buy_property(property); testing::set_contract_address(caller_2); @@ -1579,37 +1579,37 @@ mod tests { // Four HOUSES testing::set_contract_address(caller_1); actions_system.move_player(1, 40); - let mut property = actions_system.get_property(4, 1); - let mut property1 = actions_system.get_property(2, 1); + let mut property = actions_system.get_property(3, 1); + let mut property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); - property = actions_system.get_property(4, 1); - property1 = actions_system.get_property(2, 1); + property = actions_system.get_property(3, 1); + property1 = actions_system.get_property(1, 1); actions_system.buy_house_or_hotel(property); actions_system.buy_house_or_hotel(property1); @@ -1619,7 +1619,7 @@ mod tests { testing::set_contract_address(caller_2); actions_system.move_player(1, 40); - let landed_property = actions_system.get_property(4, 1); + let landed_property = actions_system.get_property(3, 1); actions_system.pay_rent(landed_property); } @@ -1670,7 +1670,7 @@ mod tests { assert(started, 'Game start fail'); testing::set_contract_address(caller_1); - actions_system.move_player(1, 4); + actions_system.move_player(1, 2); let ppt = actions_system.get_property(5, 1); let mut community = actions_system.handle_community_chest(1, 3); @@ -1756,7 +1756,7 @@ mod tests { assert(started, 'Game start fail'); testing::set_contract_address(caller_1); - actions_system.move_player(1, 4); + actions_system.move_player(1, 2); let ppt = actions_system.get_property(5, 1); @@ -1796,7 +1796,7 @@ mod tests { println!("chance 17 : {}", chance); } #[test] - fn test_process_chance() { + fn test_process_only_chance() { let caller_1 = contract_address_const::<'aji'>(); let caller_2 = contract_address_const::<'collins'>(); let caller_3 = contract_address_const::<'jerry'>(); @@ -1845,17 +1845,260 @@ mod tests { actions_system.move_player(1, 7); let mut g = actions_system.retrieve_game(1); - println!("array len b4 : {} ", g.chance.len()); - let mut p = actions_system.retrieve_game_player(caller_1, 1); let mut chance = actions_system.handle_chance(1, 3); - println!("chance 1 : {}", chance); - let (game, ply) = actions_system.process_chance_card(g, p, chance); + + let (game, ply) = actions_system.process_chance_card(g, p, chance.clone()); assert(ply.position == 12, 'position error'); assert(ply.balance == 1430, 'bal error'); } + + #[test] + fn test_process_chance_individually() { + let caller_1 = contract_address_const::<'aji'>(); + let caller_2 = contract_address_const::<'collins'>(); + + let username = 'Ajidokwu'; + let username_1 = 'Collins'; + + let ndef = namespace_def(); + let mut world = spawn_test_world([ndef].span()); + world.sync_perms_and_inits(contract_defs()); + + let (contract_address, _) = world.dns(@"actions").unwrap(); + let actions_system = IActionsDispatcher { contract_address }; + + testing::set_contract_address(caller_2); + actions_system.register_new_player(username_1); + + testing::set_contract_address(caller_1); + actions_system.register_new_player(username); + + testing::set_contract_address(caller_1); + actions_system.create_new_game(GameType::PublicGame, PlayerSymbol::Hat, 2); + + testing::set_contract_address(caller_2); + actions_system.join_game(PlayerSymbol::Dog, 1); + + testing::set_contract_address(caller_1); + let started = actions_system.start_game(1); + assert(started, 'Game start fail'); + + testing::set_contract_address(caller_1); + actions_system.move_player(1, 7); + + let mut g = actions_system.retrieve_game(1); + let mut p = actions_system.retrieve_game_player(caller_1, 1); + + let mut chance: ByteArray = "Advance to Go (Collect $200)"; + + let (_, ply) = actions_system.process_chance_card(g.clone(), p, chance); + assert(ply.position == 0, 'position error'); + assert(ply.balance == 1700, 'bal error'); + + g = actions_system.finish_turn(g); + testing::set_contract_address(caller_2); + actions_system.move_player(1, 7); + + g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_2, 1); + + chance = "Advance to MakerDAO Avenue - If you pass Go, collect $200"; + + let (_, ply) = actions_system.process_chance_card(g.clone(), p, chance); + g = actions_system.finish_turn(g); + + assert(ply.position == 24, 'position error'); + assert(ply.balance == 1500, 'bal error'); + + testing::set_contract_address(caller_1); + actions_system.move_player(1, 7); + + g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_1, 1); + + chance = "Advance to Arbitrium Avenue - If you pass Go, collect $200"; + + let (_, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 11, 'position error'); + assert(ply.balance == 1700, 'bal error'); + + testing::set_contract_address(caller_2); + actions_system.move_player(1, 12); + + g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_2, 1); + + chance = "Advance token to nearest Utility. Pay 10x dice."; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 12, 'position error'); + assert(ply.balance == 1380, 'bal error'); + + testing::set_contract_address(caller_1); + actions_system.move_player(1, 11); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_1, 1); + + chance = "Advance token to nearest Railroad. Pay 2x rent."; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 25, 'position error'); + assert(ply.balance == 1700, 'bal error'); + + testing::set_contract_address(caller_2); + actions_system.move_player(1, 10); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_2, 1); + + chance = "Bank pays you dividend of $50"; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 22, 'position error'); + assert(ply.balance == 1430, 'bal error'); + + testing::set_contract_address(caller_1); + actions_system.move_player(1, 11); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_1, 1); + + chance = "Get out of Jail Free"; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 36, 'position error'); + assert(ply.balance == 1700, 'bal error'); + assert(ply.chance_jail_card, 'get out jail error'); + + testing::set_contract_address(caller_2); + actions_system.move_player(1, 14); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_2, 1); + + chance = "Pay poor tax of $15"; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 36, 'position error'); + assert(ply.balance == 1415, 'bal error'); + + testing::set_contract_address(caller_1); + actions_system.move_player(1, 11); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_1, 1); + + chance = "Make general repairs - $25 house, $100 hotel"; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 7, 'position error'); + assert(ply.balance == 1900, 'bal error'); + + testing::set_contract_address(caller_2); + actions_system.move_player(1, 11); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_2, 1); + + chance = "Go Back 3 Spaces"; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 4, 'position error'); + assert(ply.balance == 1615, 'bal error'); + + // HERE + + testing::set_contract_address(caller_1); + actions_system.move_player(1, 15); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_1, 1); + + chance = "Make general repairs - $25 house, $100 hotel"; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 22, 'position error'); + assert(ply.balance == 1900, 'bal error'); + + testing::set_contract_address(caller_2); + actions_system.move_player(1, 3); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_2, 1); + + chance = "Take a trip to IPFS Railroad"; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 5, 'position error'); + assert(ply.balance == 1815, 'bal error'); + + testing::set_contract_address(caller_1); + actions_system.move_player(1, 14); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_1, 1); + + chance = "Take a walk on the Bitcoin Lane"; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 39, 'position error'); + assert(ply.balance == 1900, 'bal error'); + + testing::set_contract_address(caller_2); + actions_system.move_player(1, 2); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_2, 1); + + chance = "Speeding fine $200"; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 7, 'position error'); + assert(ply.balance == 1615, 'bal error'); + + testing::set_contract_address(caller_1); + actions_system.move_player(1, 8); + + let g = actions_system.retrieve_game(1); + p = actions_system.retrieve_game_player(caller_1, 1); + + chance = "Building loan matures - collect $150"; + + let (g, ply) = actions_system.process_chance_card(g.clone(), p, chance); + actions_system.finish_turn(g); + + assert(ply.position == 7, 'position error'); + assert(ply.balance == 2250, 'bal error'); + } + #[test] fn test_process_community_chest() { let caller_1 = contract_address_const::<'aji'>(); @@ -1903,20 +2146,18 @@ mod tests { assert(started, 'Game start fail'); testing::set_contract_address(caller_1); - actions_system.move_player(1, 3); + actions_system.move_player(1, 2); let mut g = actions_system.retrieve_game(1); - println!("array len b4 : {} ", g.chance.len()); let mut p = actions_system.retrieve_game_player(caller_1, 1); - let mut community_chest = actions_system.handle_community_chest(1, 3); - println!("community_chest: {}", community_chest); + let mut community_chest = actions_system.handle_community_chest(1, 2); - let (_, ply) = actions_system.process_community_chest_card(g, p, community_chest); + let (_, ply) = actions_system.process_community_chest_card(g, p, community_chest.clone()); - assert(ply.position == 3, 'position error'); - assert(ply.balance == 1550, 'bal error'); + assert(ply.position == 2, 'position error'); + assert(ply.balance == 1450, 'bal error'); } }