tipc19py.py

Created by andreanx

Created on October 02, 2019

3.21 KB

Script for the TI-Planet & Planète Casio back to school 2019 contest. Check https://tiplanet.org/forum/viewtopic.php?t=23011


#cas
from math import *
def mmod(a,b):
  return a%b
def getplatform():
  return 1
def getlinechars(o=False):
  c,k=2**31-1,getplatform()
  if k>=0:
    c=[53,o and 99 or 29,o and 509 or 21,31,32,c,c][k]
  return c
na,pkl,lnm=21,[],["Bulbizarre","Herbizarre","Florizarre","Salameche","Reptincel","Dracaufeu","Carapuce","Carabaffe","Tortank","Chenipan","Chrysacier","Papilusion","Aspicot","Coconfort","Dardargnan","Roucool","Roucoups","Roucarnage","Rattata","Rattatac","Piafabec","Rapasdepic","Abo","Arbok","Pikachu","Raichu","Sabelette","Sablaireau","Nidoran F","Nidorina","Nidoqueen","Nidoran M","Nidorino","Nidoking","Melofee","Melodelfe","Goupix","Feunard","Rondoudou","Grodoudou","Nosferapti","Nosferalto","Mystherbe","Ortide","Rafflesia","Paras","Parasect","Mimitoss","Aeromite","Taupiqueur","Triopikeur","Miaouss","Persian","Psykokwak","Akwakwak","Ferosinge","Colossinge","Caninos","Arcanin","Ptitard","Tetarte","Tartard","Abra","Kadabra","Alakazam","Machoc","Machopeur","Mackogneur","Chetiflor","Boustiflor","Empiflor","Tentacool","Tentacruel","Racaillou","Gravalanch","Grolem","Ponyta","Galopa","Ramoloss","Flagadoss","Magneti","Magneton","Canarticho","Doduo","Dodrio","Otaria","Lamantine","Tadmorv","Grotadmorv","Kokiyas","Crustabri","Fantominus","Spectrum","Ectoplasma"]
mrandmax,mrand,mfmax,nn,mp=2**31-1,0,93,getlinechars(True)-na,na//2
def mround(f):
  d=mmod(abs(f),1)
  return (mfloor(abs(f))+(d>=.5))*(1-2*(f<0))
def mfloor(f):
  return round(f)-(round(f)>f)
def mceil(f):
  return round(f)+(round(f)<f)
def mseed(s):
  global mrand
  mrand=mmod(s,mrandmax)
def mrandom():
  mseed(mrand*16807)
  return float(mrand/mrandmax)
def muniform(mini,maxi):
  return mrandom()*(maxi-mini)+mini
def mrandint(mini,maxi):
  return mround(muniform(mceil(mini),mfloor(maxi)))
def f2mf(f):
  return mround(float(f*mfmax))
def mf2f(n):
  return float(n/mfmax)
def mbit(a,b):
  return mmod((a//(2**b)),2)
def getattack(p,pts):
  global pkt
  mseed(42)
  for k in range(p+1):
    mrandom()
  a,pka=mrandint(1,mrandmax),""
  for j in range(na):
    if mbit(a,j)!=0:
      pka+="X"
      pkt[j]+=pts
    else:
      pka+=" -"[getplatform()>=5]
  return pka
def i2c(k):
  return chr(k+33)
def c2i(c):
  return ord(c)-33
def clean():
  global pkl
  t,s=0,0
  for l in pkl:
    t+=l[1]
  for l in pkl:
    l[2]=f2mf(l[1]/(t or 1))
    s+=l[2]
    if(l[2]<=0):
      pkl.remove(l)
      return clean()
  return s
def pk(n,p=1,d=2):
  global pkt, pkl
  n-=1
  if n>=0 and n<len(lnm):
    new=True
    for k in range(len(pkl)):
      if pkl[k][0]==n:
        new,pkl[k][1]=False,max(p,0)
    if new and len(pkl)<mp:
      pkl.append([n,max(p,0),0])
  ptt,pkt,t,st=clean(),[0 for k in range(na)],0,""
  for l in pkl:
    s=getattack(l[0],l[2]/ptt)
    if d:
      sn=" "+lnm[l[0]]
      if len(sn)>nn:
        sn=sn[:nn]
      print(s+sn)
    st=i2c(l[0])+st+i2c(l[2])
  for k in pkt:
    if(k):
      t+=log(e+k*len(pkl))
  if(d):
    if(d>=2):
      print("Bon score ? Si oui\nenvoie code suivant\na info@tiplanet.org :")
    print(""+st)
  return float(t)
def setst(st):
  s,pkl[:],n=0,[],len(st)//2
  for k in range(n):
    s=pk(c2i(st[n-1-k])+1,c2i(st[n+k+len(st)%2]),k+1>=n)
  return s
print("pk(n,p) pour rajouter\nle Pokemon n a ta main\navec p points d'attaque.")
#end

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.