Best Python code snippet using sure_python
woodcutting.py
Source:woodcutting.py
1# Script for Woodcutting Skill2# Author: Ryan/Lmctruck303# 4#5# Stump: 1341(deadtree)6import random7from server.model.players import PlayerHandler8from server.util import Misc9from server.task import TaskManager10from server.task import TaskFactory11# ITEM ACTION LISTENERS12# Normal Trees13def objectAction1_1276(player, objX, objY):14 doAxeCheck(player, "TREE", 1276, objX, objY)15def objectAction1_1277(player, objX, objY):16 doAxeCheck(player, "TREE", 1277, objX, objY)17def objectAction1_1278(player, objX, objY):18 doAxeCheck(player, "TREE", 1278, objX, objY)19def objectAction1_1279(player, objX, objY):20 doAxeCheck(player, "TREE", 1279, objX, objY)21def objectAction1_1280(player, objX, objY):22 doAxeCheck(player, "TREE", 1280, objX, objY)23def objectAction1_1282(player, objX, objY):24 doAxeCheck(player, "TREE", 1282, objX, objY)25def objectAction1_1283(player, objX, objY):26 doAxeCheck(player, "TREE", 1283, objX, objY)27def objectAction1_1284(player, objX, objY):28 doAxeCheck(player, "TREE", 1284, objX, objY)29def objectAction1_1285(player, objX, objY):30 doAxeCheck(player, "TREE", 1285, objX, objY)31def objectAction1_1286(player, objX, objY):32 doAxeCheck(player, "TREE", 1286, objX, objY)33def objectAction1_1289(player, objX, objY):34 doAxeCheck(player, "TREE", 1289, objX, objY)35def objectAction1_1290(player, objX, objY):36 doAxeCheck(player, "TREE", 1290, objX, objY)37def objectAction1_1291(player, objX, objY):38 doAxeCheck(player, "TREE", 1291, objX, objY)39def objectAction1_1315(player, objX, objY):40 doAxeCheck(player, "TREE", 1315, objX, objY)41def objectAction1_1316(player, objX, objY):42 doAxeCheck(player, "TREE", 1316, objX, objY)43def objectAction1_1318(player, objX, objY):44 doAxeCheck(player, "TREE", 1318, objX, objY)45def objectAction1_1319(player, objX, objY):46 doAxeCheck(player, "TREE", 1319, objX, objY)47def objectAction1_1330(player, objX, objY):48 doAxeCheck(player, "TREE", 1330, objX, objY)49def objectAction1_1331(player, objX, objY):50 doAxeCheck(player, "TREE", 1331, objX, objY)51def objectAction1_1332(player, objX, objY):52 doAxeCheck(player, "TREE", 1332, objX, objY)53def objectAction1_1365(player, objX, objY):54 doAxeCheck(player, "TREE", 1365, objX, objY)55def objectAction1_1383(player, objX, objY):56 doAxeCheck(player, "TREE", 1383, objX, objY)57def objectAction1_1384(player, objX, objY):58 doAxeCheck(player, "TREE", 1384, objX, objY)59def objectAction1_2409(player, objX, objY):60 doAxeCheck(player, "TREE", 2409, objX, objY)61def objectAction1_3033(player, objX, objY):62 doAxeCheck(player, "TREE", 3033, objX, objY)63def objectAction1_3034(player, objX, objY):64 doAxeCheck(player, "TREE", 3034, objX, objY)65def objectAction1_3035(player, objX, objY):66 doAxeCheck(player, "TREE", 3035, objX, objY)67def objectAction1_3036(player, objX, objY):68 doAxeCheck(player, "TREE", 3036, objX, objY)69def objectAction1_3881(player, objX, objY):70 doAxeCheck(player, "TREE", 3881, objX, objY)71def objectAction1_3882(player, objX, objY):72 doAxeCheck(player, "TREE", 3882, objX, objY)73def objectAction1_3883(player, objX, objY):74 doAxeCheck(player, "TREE", 3883, objX, objY)75def objectAction1_5902(player, objX, objY):76 doAxeCheck(player, "TREE", 5902, objX, objY)77def objectAction1_5203(player, objX, objY):78 doAxeCheck(player, "TREE", 5203, objX, objY)79def objectAction1_5304(player, objX, objY):80 doAxeCheck(player, "TREE", 5304, objX, objY)81# Oak Trees82def objectAction1_1281(player, objX, objY):83 doAxeCheck(player, "OAK", 1281, objX, objY)84def objectAction1_1306(player, objX, objY):85 doAxeCheck(player, "OAK", 1306, objX, objY)86# Willow Trees87def objectAction1_1308(player, objX, objY):88 doAxeCheck(player, "WILLOW", 1308, objX, objY)89def objectAction1_5551(player, objX, objY):90 doAxeCheck(player, "WILLOW", 5551, objX, objY)91def objectAction1_5552(player, objX, objY):92 doAxeCheck(player, "WILLOW", 5552, objX, objY)93def objectAction1_5553(player, objX, objY):94 doAxeCheck(player, "WILLOW", 5553, objX, objY) 95# Yew Trees96def objectAction1_1309(player, objX, objY):97 doAxeCheck(player, "YEW", 1309, objX, objY)98# Magic Trees99def objectAction1_1292(player, objX, objY):100 doAxeCheck(player, "MAGE", 1292, objX, objY)101def objectAction1_1306(player, objX, objY):102 doAxeCheck(player, "WILLOW", 1306, objX, objY)103# AXE CHECK104def doAxeCheck(player, name, objID, objX, objY):105 level = player.playerLevel[8]106 if player.withinInteractionDistance(objX, objY):107 if player.freeSlots() > 0:108 if player.hasItem(6739) and level >= 61:109 doCut(player, name, objID, objX, objY)110 elif player.hasItem(1359) and level >= 41:111 doCut(player, name, objID, objX, objY)112 elif player.hasItem(1357) and level >= 31:113 doCut(player, name, objID, objX, objY)114 elif player.hasItem(1355) and level >= 21:115 doCut(player, name, objID, objX, objY)116 elif player.hasItem(1353) and level >= 6 or player.hasItem(1361) and level >= 6:117 doCut(player, name, objID, objX, objY)118 elif player.hasItem(1351) or player.hasItem(1349):119 doCut(player, name, objID, objX, objY)120 else:121 player.sendMessage("You do not have a axe of which you have the level to use.")122 elif player.freeSlots() == 0:123 player.resetAnimation()124 player.sendMessage("You don't have enough inventory space to do that.")125# SKILL EXECUTION126def doCut(player, name, objID, x, y):127 level = player.playerLevel[8]128 if name == "TREE":129 player.sendMessage("You swing your axe at the tree...")130 player.setAnimation(867)131 TaskManager.registerClientTask(TaskFactory.getDelayedTask("callback_woodcutting_TREE", player, objID, x, y), random.randrange(1, 4))132 elif name == "OAK":133 if level >= 15:134 player.sendMessage("You swing your axe at the tree...")135 player.setAnimation(867)136 TaskManager.registerClientTask(TaskFactory.getDelayedTask("callback_woodcutting_OAK", player, objID, x, y), random.randrange(3, 6))137 else:138 player.sendMessage("You need a woodcutting level of 15 to cut this tree.")139 elif name == "WILLOW":140 if level >= 30:141 player.sendMessage("You swing your axe at the tree...")142 player.setAnimation(867)143 TaskManager.registerClientTask(TaskFactory.getDelayedTask("callback_woodcutting_WILLOW", player, objID, x, y), random.randrange(3, 8))144 else:145 player.sendMessage("You need a woodcutting level of 30 to cut this tree.")146 elif name == "YEW":147 if level >= 60:148 player.sendMessage("You swing your axe at the tree...")149 player.setAnimation(867)150 TaskManager.registerClientTask(TaskFactory.getDelayedTask("callback_woodcutting_YEW", player, objID, x, y), random.randrange(3, 12))151 else:152 player.sendMessage("You need a woodcutting level of 60 to cut this tree.")153 154 155# SKILL CALLBACK FUNCTIONS156def callback_woodcutting_TREE(player, id, x, y):157 player.sendMessage("You get some logs.")158 player.addItem(1511, 1)159 player.addSkillXP(50, 8)160 if random.randrange(1 , 2) == 1:161 player.resetAnimation()162 PlayerManager.replaceObjectGlobal(x, y, 1341, 0, 10)163 TaskManager.registerClientTask(TaskFactory.getDelayedGlobalTask("callback_woodcutting_replace", id, x, y), 3)164 else:165 doAxeCheck(player, "TREE", id, x, y)166def callback_woodcutting_OAK(player, id, x, y):167 player.sendMessage("You get some oak logs.")168 player.addItem(1519, 1)169 player.addSkillXP(75, 8)170 if Misc.random(4) == 1:171 player.resetAnimation()172 PlayerManager.replaceObjectGlobal(x, y, 1341, 0, 10)173 TaskManager.registerClientTask(TaskFactory.getDelayedGlobalTask("callback_woodcutting_replace", id, x, y), 5)174 else:175 doAxeCheck(player, "OAK", id, x, y)176def callback_woodcutting_WILLOW(player, id, x, y):177 player.sendMessage("You get some willow logs.")178 player.addItem(1521, 1)179 player.addSkillXP(135, 8)180 if Misc.random(6) == 1:181 player.resetAnimation()182 PlayerManager.replaceObjectGlobal(x, y, 1341, 0, 10)183 TaskManager.registerClientTask(TaskFactory.getDelayedGlobalTask("callback_woodcutting_replace", id, x, y), 8)184 else:185 doAxeCheck(player, "WILLOW", id, x, y)186def callback_woodcutting_YEW(player, id, x, y):187 player.sendMessage("You get some willow logs.")188 player.addItem(1515, 1)189 player.addSkillXP(350, 8)190 if Misc.random(6) == 1:191 player.resetAnimation()192 PlayerManager.replaceObjectGlobal(x, y, 1341, 0, 10)193 TaskManager.registerClientTask(TaskFactory.getDelayedGlobalTask("callback_woodcutting_replace", id, x, y), 8)194 else:195 doAxeCheck(player, "YEW", id, x, y)196# OBJECT RESPAWN197def callback_woodcutting_replace(id, x, y):...
working-2SG.py
Source:working-2SG.py
1# importing Numpy for some necessary operations2import numpy as np3# =============================4# Welcome to the 2 Squares Game! 5# ------------------------------6#|| 01 | 02 | 03 | 04 || 7# ---------------------------8#|| 05 | 06 | 07 | 08 || 9# ---------------------------10#|| 09 | 10 | 11 | 12 || 11# ---------------------------12#|| 13 | 14 | 15 | 16 || 13# =============================14# Author: CS112 - 2022 & | Moustafa Aly Hashem | ID: 2021039415# Version: 1.016# Date: 10 March 202217# 1- Build game board18# 2- Display game board19# 3- nActions = 020# 4- While (nActions != 8) 21# 5- Get player X action22# 6- Update game board23# 7- Get player O action24# 8- Update game board25# 9- If 2 cells are left26# - see their values27# - if adjacent -> x wins28# - if not -> o wins29# 10- if (nActions == 8)30# 10.a Break31# 11- nActions += 132# 12- Print ("Draw")33board = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', \34 '14', '15', '16']35# Displaying the board 1st time...36def display_board():37 print (" =============================")38 print (" Welcome to the 2 Squares Game! ")39 print (" ------------------------------")40 print ("|| " , board[0], " | ", board[1], " | ", board[2], " | ", board[3], " || ")41 print (" ---------------------------")42 print ("|| " , board[4], " | ", board[5], " | ", board[6], " | ", board[7], " || ")43 print (" ---------------------------")44 print ("|| ", board[8], " | ", board[9], " | ", board[10], " | ", board[11], " || ")45 print (" ---------------------------")46 print ("|| ", board[12], " | ", board[13], " | ", board[14], " | ", board[15], " || ")47 #print (" ---------------------------")48 print (" =============================")49# Get 1st response from player50def get_player_action1 (player):51 is_valid = False52 message1 = "Please choose 1st cell from 1 to 16 for player " + player + ": "53 global action154 while (not is_valid):55 action1 = input (message1)56 if not (action1).isdigit():57 continue58 else:59 is_valid = True60 action1 = int(action1)61 is_valid = is_valid and int(action1) > 0 and int(action1) <= 1662 is_valid = is_valid and board[action1 -1] != 'X'63 return action164#temp = action165# Get 2nd response from player66def get_player_action2 (player):67 is_valid = False68 message2 = "Please choose 2nd cell from 1 to 16 for player " + player + ": "69 while (not is_valid):70 action2 = input (message2)71 if not (action2).isdigit():72 continue73 else:74 is_valid = True75 action2 = int(action2)76 is_valid = is_valid and int(action2) > 0 and int(action2) <= 1677 is_valid = is_valid and board[action2 -1] != 'X'78 #Goto label;79 return action280def update_game_board (action1, action2, player):81 board [action1 - 1] = player82 board [action2 - 1] = player83 display_board()84def is_winner():85 counter = 086 for i in board:87 temp1 = np.zeros(16)88 if (i != 'XX'):89 counter = counter + 190 temp1[counter] = i91 if (counter == 2):92 if ((abs(temp1[1] - temp1[2]) != 1) and \93 (abs(temp1[1] - temp1[2]) != 4)):94 cond = True95 else:96 cond = False97 return cond98def play_game():99 display_board()100 n_actions = 0101 while (n_actions != 8):102 # Flags initialization103 flag_x = True104 flag_o = True105 boarders1 = False106 boarders2 = False107 action1 = get_player_action1 ('X')108 action2 = get_player_action2 ('X')109 #=================================110 # wrong input from player X111 #=================================112 while(flag_x):113 if ((int(action1)==4 or int(action1)==8 or int(action1)==12) and \114 (int(action2)==5 or int(action2)==9 or int(action2)==13)):115 boarders1 = True116 elif ((int(action2)==4 or int(action2)==8 or int(action2)==12) and \117 (int(action1)==5 or int(action1)==9 or int(action1)==13)):118 boarders2 = True119 else:120 boarders1 = False121 boarders2 = False122 if ((abs(int(action1) - int(action2)) > 1) and \123 (abs(int(action1) - int(action2)) != 4)):124 print ('Attention! 2nd input is not valid! please enter an adjacent cell')125 action2 = get_player_action2 ('X')126 elif(boarders1 or boarders2):127 print ('Attention! 2nd input is not valid! please enter an adjacent cell')128 action2 = get_player_action2 ('X')129 elif(abs(int(action1) == int(action2))):130 print ('Attention! 2nd input was entered before! please choose another cell')131 action2 = get_player_action2 ('X')132 else:133 flag_x = False134 #=================================135 # updating the board with actions from player X136 update_game_board (action1, action2, 'XX')137 if (is_winner()):138 print ('X wins! CONGRATULATIONS!!')139 break140 n_actions += 1141 if (n_actions == 8):142 break143 # Getting actions from player O144 action1 = get_player_action1 ('O')145 action2 = get_player_action2 ('O')146 #=================================147 # wrong input from player O148 #=================================149 while(flag_o):150 if ((int(action1)==4 or int(action1)==8 or int(action1)==12) and \151 (int(action2)==5 or int(action2)==9 or int(action2)==13)):152 boarders1 = True153 elif ((int(action2)==4 or int(action2)==8 or int(action2)==12) and \154 (int(action1)==5 or int(action1)==9 or int(action1)==13)):155 boarders2 = True156 else:157 boarders1 = False158 boarders2 = False159 if ((abs(int(action1) - int(action2)) > 1) and \160 (abs(int(action1) - int(action2)) != 4)):161 print ('Attention! 2nd input is not valid! please enter an adjacent cell')162 action2 = get_player_action2 ('X')163 elif((boarders1 or boarders2)):164 print ('Attention! 2nd input is not valid! please enter an adjacent cell')165 action2 = get_player_action2 ('X')166 elif(abs(int(action1) == int(action2))):167 print ('Attention! 2nd input was entered before! please choose another cell')168 action2 = get_player_action2 ('X')169 else:170 flag_o = False171 #=================================172 # updating the board with actions from player O173 update_game_board (action1, action2, 'XX')174 if (is_winner()):175 print ('O wins! CONGRATULATIONS!!')176 break177 n_actions += 1178 if (not is_winner()):179 print ('Draw')180#############################...
rewards.py
Source:rewards.py
1#!/usr/bin/env python2import math3from random import *4def rewardA(tigerDoor, action0, action1, agent0, agent1):5 if tigerDoor == 1:6 if action0 == 2 and action1 == 2:7 listened = 08 reward = 209 print("reward = " + repr(reward))10 elif action0 == 1 and action1 == 1:11 listened = 012 reward = -5013 print("reward = " + repr(reward))14 elif action0 == 2 and action1 == 1: 15 listened = 016 reward = -10017 print("reward = " + repr(reward))18 elif action0 == 1 and action1 == 2:19 listened = 020 reward = -10021 print("reward = " + repr(reward))22 elif action0 == 3 and action1 == 3:23 agent0 = 0.8524 agent1 = 0.8525 listened = 126 reward = -227 print("reward = " + repr(reward))28 elif action0 == 3 and action1 == 2:29 listened = 030 reward = 931 print("reward = " + repr(reward))32 elif action0 == 2 and action1 == 3:33 listened = 034 reward = 935 print("reward = " + repr(reward))36 elif action0 == 3 and action1 == 1:37 listened = 038 reward = -10139 print("reward = " + repr(reward))40 elif action0 == 1 and action1 == 3:41 listened = 042 reward = -10143 print("reward = " + repr(reward))44 elif tigerDoor == 2:45 if action0 == 2 and action1 == 2:46 listened = 047 reward = -5048 print("reward = " + repr(reward))49 elif action0 == 1 and action1 == 1:50 listened = 051 reward = 2052 print("reward = " + repr(reward))53 elif action0 == 2 and action1 == 1: 54 listened = 055 reward = -10056 print("reward = " + repr(reward))57 elif action0 == 1 and action1 == 2:58 listened = 059 reward = -10060 print("reward = " + repr(reward))61 elif action0 == 3 and action1 == 3:62 agent0 = 0.1563 agent1 = 0.1564 listened = 165 reward = -266 print("reward = " + repr(reward))67 elif action0 == 3 and action1 == 2:68 listened = 069 reward = -10170 print("reward = " + repr(reward))71 elif action0 == 2 and action1 == 3:72 listened = 073 reward = -10174 print("reward = " + repr(reward))75 elif action0 == 3 and action1 == 1:76 listened = 077 reward = 978 print("reward = " + repr(reward))79 elif action0 == 1 and action1 == 3:80 listened = 081 reward = 982 print("reward = " + repr(reward))83 else:84 print("Something went wrong with creating the tigerDoor")85 return listened, reward, agent0, agent186def rewardB(tigerDoor, action0, action1):87 if tigerDoor == 1:88 if action0 == 2 and action1 == 2:89 listened = 090 reward = 2091 print("reward = " + repr(reward))92 elif action0 == 1 and action1 == 1:93 listened = 094 reward = -5095 print("reward = " + repr(reward))96 elif action0 == 2 and action1 == 1: 97 listened = 098 reward = -10099 print("reward = " + repr(reward))100 elif action0 == 1 and action1 == 2:101 listened = 0102 reward = -100103 print("reward = " + repr(reward))104 elif action0 == 3 and action1 == 3:105 agent0 = 0.85106 agent1 = 0.85107 listened = 1108 reward = -2109 print("reward = " + repr(reward))110 elif action0 == 3 and action1 == 2:111 listened = 0112 reward = 9113 print("reward = " + repr(reward))114 elif action0 == 2 and action1 == 3:115 listened = 0116 reward = 9117 print("reward = " + repr(reward))118 elif action0 == 3 and action1 == 1:119 listened = 0120 reward = -101121 print("reward = " + repr(reward))122 elif action0 == 1 and action1 == 3:123 listened = 0124 reward = -101125 print("reward = " + repr(reward))126 elif tigerDoor == 2:127 if action0 == 2 and action1 == 2:128 listened = 0129 reward = -50130 print("reward = " + repr(reward))131 elif action0 == 1 and action1 == 1:132 listened = 0133 reward = 20134 print("reward = " + repr(reward))135 elif action0 == 2 and action1 == 1: 136 listened = 0137 reward = -100138 print("reward = " + repr(reward))139 elif action0 == 1 and action1 == 2:140 listened = 0141 reward = -100142 print("reward = " + repr(reward))143 elif action0 == 3 and action1 == 3:144 agent0 = 0.15145 agent1 = 0.15146 listened = 1147 reward = -2148 print("reward = " + repr(reward))149 elif action0 == 3 and action1 == 2:150 listened = 0151 reward = -101152 print("reward = " + repr(reward))153 elif action0 == 2 and action1 == 3:154 listened = 0155 reward = -101156 print("reward = " + repr(reward))157 elif action0 == 3 and action1 == 1:158 listened = 0159 reward = 9160 print("reward = " + repr(reward))161 elif action0 == 1 and action1 == 3:162 listened = 0163 reward = 9164 print("reward = " + repr(reward))165 else:166 print("Something went wrong with creating the tigerDoor")...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!