You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

player1.cpp 92 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902
  1. #include <vector>
  2. #include <thread>
  3. #include <array>
  4. #include "AI.h"
  5. #include "constants.h"
  6. #include<math.h>
  7. #include<queue>
  8. #include<list>
  9. #include<algorithm>
  10. #include<chrono>
  11. #include <iostream>
  12. #define P2I 0.785398163397425
  13. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  14. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  15. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  16. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  17. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  18. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  19. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  20. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  21. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  22. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  23. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  24. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  25. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  26. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  27. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  28. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  29. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  30. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  31. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  32. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  33. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  34. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!//一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  35. //一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!一切恐惧源于性能不足!!!
  36. // 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新
  37. extern const bool asynchronous = false;
  38. // 选手需要依次将player0到player4的职业在这里定义
  39. extern const std::array<THUAI6::StudentType, 4> studentType = {
  40. THUAI6::StudentType::Teacher,
  41. THUAI6::StudentType::StraightAStudent,
  42. THUAI6::StudentType::Teacher,
  43. THUAI6::StudentType::StraightAStudent };
  44. extern const THUAI6::TrickerType trickerType = THUAI6::TrickerType::Klee;
  45. struct mapnode {
  46. int x, y;
  47. };
  48. static std::vector<mapnode> path;
  49. static int scurstate = 3;
  50. static bool initialized;
  51. static std::vector< std::vector<int>> wallmap(50, std::vector<int>(50));
  52. static std::vector<mapnode> homeworkmap;
  53. //卷图,标记作业进度
  54. static int juanmap[10] = { 0 };
  55. static std::vector<mapnode> xiaomenmap;
  56. static std::vector<mapnode> grassmap;
  57. static int juaned[10] = { 0 };
  58. //static std::vector<mapnode> routemap = { {22,15},{25,7},{40,20},{41,31},{30,35},{15,40},{8,35} };
  59. static std::vector<mapnode> routemap = { {6,25},{4,31},{14,39},{21,44},{23,40},{29,34},{29,25},{40,24},{25,6},{15,15} };
  60. static std::vector<mapnode> routemap2 = { {31,4},{41,4},{45,8},{45,20},{45,29},{30,31},{21,31},{20,45},{8,45},{4,40}, {4,29} , {4,20}, {19,18}, {28,18} };
  61. //mapflag 0为1图,1为2图
  62. static bool mapflag;
  63. void Move(mapnode n1, mapnode n2);
  64. struct info {
  65. mapnode nownode;
  66. mapnode nowgrid;
  67. double CD[3];
  68. //std::string message;
  69. double dangeralert;
  70. std::vector<std::shared_ptr<const THUAI6::Tricker>> trickerinfo;
  71. };
  72. static int direction = 0;
  73. static bool captain = false;
  74. //Astar的锁
  75. static bool unlockAstar = 1;
  76. //发送集合消息的锁
  77. static bool unlockpos = 1;
  78. //是否开始写作业的锁
  79. const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
  80. const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };
  81. //走路用的迭代器
  82. static int counter = 0;
  83. //状态表
  84. static int curstate = 4;
  85. //上一次tonode
  86. static mapnode lastpos = { -1,-1 };
  87. //上一次位置
  88. static mapnode lastgrid = { -1,-1 };
  89. //卡人角度
  90. static int d30x[4] = { 700,400,-700,-400 };
  91. static int d30y[4] = { -400,700,400,-700 };
  92. //作业是否写完
  93. static bool juanedmap[10] = { 0 };
  94. //辅助计算函数
  95. //1.计算距离
  96. double distant(mapnode A, mapnode B) {
  97. return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
  98. }
  99. //2.计算最短路径
  100. //以下是我网上抄的一个A星算法,实例化以后(如 Astar A),直接用A.savetopath(格点 A,格点 B,路径 path),路会自动存到path里,每次存之前会自动清空path,不要使用其他接口,不要改变其中的变量
  101. //***********************************************************************************************************************
  102. const int kCost1 = 10;
  103. const int kCost2 = 14;
  104. struct Point
  105. {
  106. int x, y; //点坐标,这里为了方便按照C++的数组来计算,x代表横排,y代表竖列
  107. int F, G, H; //F=G+H
  108. Point* parent; //parent的坐标,这里没有用指针,从而简化代码
  109. Point(int _x, int _y)//变量初始化
  110. {
  111. x = _x;
  112. y = _y;
  113. F = 0;
  114. G = 0;
  115. H = 0;
  116. parent = NULL;
  117. }
  118. };
  119. class Astar
  120. {
  121. public:
  122. void InitAstar(std::vector<std::vector<int>>& _maze);
  123. std::list<Point*> GetPath(Point& startPoint, Point& endPoint, bool isIgnoreCorner);
  124. void savetopath(mapnode A, mapnode B, std::vector<mapnode>& path);
  125. private:
  126. Point* findPath(Point& startPoint, Point& endPoint, bool isIgnoreCorner);
  127. std::vector<Point*> getSurroundPoints(const Point* point, bool isIgnoreCorner) const;
  128. bool isCanreach(const Point* point, const Point* target, bool isIgnoreCorner) const; //判断某点是否可以用于下一步判断
  129. Point* isInList(const std::list<Point*>& list, const Point* point) const; //判断开启/关闭列表中是否包含某点
  130. Point* getLeastFpoint(); //从开启列表中返回F值最小的节点
  131. //计算FGH值
  132. int calcG(Point* temp_start, Point* point);
  133. int calcH(Point* point, Point* end);
  134. int calcF(Point* point);
  135. private:
  136. std::vector<std::vector<int>> maze;
  137. std::list<Point*> openList; //开启列表
  138. std::list<Point*> closeList; //关闭列表
  139. };
  140. void Astar::savetopath(mapnode A, mapnode B, std::vector<mapnode>& path) {
  141. path.resize(0);
  142. Point start(A.x, A.y);
  143. Point end(B.x, B.y);
  144. auto road = GetPath(start, end, false);
  145. for (auto& point : road) {
  146. path.push_back({ point->x,point->y });
  147. }
  148. }
  149. void Astar::InitAstar(std::vector<std::vector<int>>& _maze)
  150. {
  151. maze = _maze;
  152. }
  153. int Astar::calcG(Point* temp_start, Point* point)
  154. {
  155. int extraG = (abs(point->x - temp_start->x) + abs(point->y - temp_start->y)) == 1 ? kCost1 : kCost2;//条件表达式,第一个真就是b,不然是c
  156. int parentG = point->parent == NULL ? 0 : point->parent->G; //如果是初始节点,则其父节点是空
  157. return parentG + extraG;
  158. }
  159. int Astar::calcH(Point* point, Point* end)
  160. {
  161. return ((end->x - point->x) + end->y - point->y) * kCost1;//欧几里得距离
  162. }
  163. int Astar::calcF(Point* point)
  164. {
  165. return point->G + point->H;
  166. }
  167. Point* Astar::getLeastFpoint()
  168. {
  169. if (!openList.empty())
  170. {
  171. auto resPoint = openList.front();
  172. for (auto& point : openList)
  173. if (point->F < resPoint->F)
  174. resPoint = point;
  175. return resPoint;
  176. }
  177. return NULL;
  178. }
  179. Point* Astar::findPath(Point& startPoint, Point& endPoint, bool isIgnoreCorner)
  180. {
  181. openList.push_back(new Point(startPoint.x, startPoint.y)); //置入起点,拷贝开辟一个节点,内外隔离
  182. while (!openList.empty())
  183. {
  184. auto curPoint = getLeastFpoint(); //找到F值最小的点
  185. openList.remove(curPoint); //从开启列表中删除
  186. closeList.push_back(curPoint); //放到关闭列表
  187. //1,找到当前周围八个格中可以通过的格子
  188. auto surroundPoints = getSurroundPoints(curPoint, isIgnoreCorner);
  189. for (auto& target : surroundPoints)
  190. {
  191. //2,对某一个格子,如果它不在开启列表中,加入到开启列表,设置当前格为其父节点,计算F G H
  192. if (!isInList(openList, target))
  193. {
  194. target->parent = curPoint;
  195. target->G = calcG(curPoint, target);
  196. target->H = calcH(target, &endPoint);
  197. target->F = calcF(target);
  198. openList.push_back(target);
  199. }
  200. //3,对某一个格子,它在开启列表中,计算G值, 如果比原来的大, 就什么都不做, 否则设置它的父节点为当前点,并更新G和F
  201. else
  202. {
  203. int tempG = calcG(curPoint, target);
  204. if (tempG < target->G)
  205. {
  206. target->parent = curPoint;
  207. target->G = tempG;
  208. target->F = calcF(target);
  209. }
  210. }
  211. Point* resPoint = isInList(openList, &endPoint);
  212. if (resPoint)
  213. return resPoint; //返回列表里的节点指针,不要用原来传入的endpoint指针,因为发生了深拷贝
  214. }
  215. }
  216. return NULL;
  217. }
  218. std::list<Point*> Astar::GetPath(Point& startPoint, Point& endPoint, bool isIgnoreCorner)
  219. {
  220. Point* result = findPath(startPoint, endPoint, isIgnoreCorner);
  221. std::list<Point*> path;
  222. //返回路径,如果没找到路径,返回空链表
  223. while (result)
  224. {
  225. path.push_front(result);
  226. result = result->parent;
  227. }
  228. // 清空临时开闭列表,防止重复执行GetPath导致结果异常
  229. openList.clear();
  230. closeList.clear();
  231. return path;
  232. }
  233. Point* Astar::isInList(const std::list<Point*>& list, const Point* point) const
  234. {
  235. //判断某个节点是否在列表中,这里不能比较指针,因为每次加入列表是新开辟的节点,只能比较坐标
  236. for (auto p : list)
  237. if (p->x == point->x && p->y == point->y)
  238. return p;
  239. return NULL;
  240. }
  241. bool Astar::isCanreach(const Point* point, const Point* target, bool isIgnoreCorner) const
  242. {
  243. if (target->x<0 || target->x>maze.size() - 1
  244. || target->y<0 || target->y>maze[0].size() - 1
  245. || maze[target->x][target->y] == 0//0代表障碍物
  246. || target->x == point->x && target->y == point->y
  247. || isInList(closeList, target)) //如果点与当前节点重合、超出地图、是障碍物、或者在关闭列表中,返回false
  248. return false;
  249. else
  250. {
  251. if (abs(point->x - target->x) + abs(point->y - target->y) == 1) //非斜角可以
  252. return true;
  253. else
  254. {
  255. //斜对角要判断是否绊住
  256. if (maze[point->x][target->y] != 0 && maze[target->x][point->y] != 0 && maze[target->x][target->y] != 2)
  257. return true;
  258. else
  259. return isIgnoreCorner;
  260. }
  261. }
  262. }
  263. std::vector<Point*> Astar::getSurroundPoints(const Point* point, bool isIgnoreCorner) const
  264. {
  265. std::vector<Point*> surroundPoints;
  266. for (int x = point->x - 1; x <= point->x + 1; x++)
  267. for (int y = point->y - 1; y <= point->y + 1; y++)
  268. if (isCanreach(point, new Point(x, y), isIgnoreCorner))
  269. surroundPoints.push_back(new Point(x, y));
  270. return surroundPoints;
  271. }
  272. static int tcurstate = 1;
  273. void pathmerging(mapnode A, mapnode B, std::vector<mapnode>& path, IStudentAPI& api) {
  274. //api.Print("1");
  275. path.resize(0);
  276. //api.Print("2");
  277. counter = 0;
  278. Astar Astar;
  279. //api.Print("3");
  280. Astar.InitAstar(wallmap);
  281. //api.Print("4");
  282. Astar.savetopath(A, B, path);
  283. //api.Print("5");
  284. }
  285. void pathmerging(mapnode A, mapnode B, std::vector<mapnode>& path, ITrickerAPI& api) {
  286. //api.Print("1");
  287. path.resize(0);
  288. //api.Print("2");
  289. counter = 0;
  290. Astar Astar;
  291. //api.Print("3");
  292. Astar.InitAstar(wallmap);
  293. //api.Print("4");
  294. Astar.savetopath(A, B, path);
  295. //api.Print("5");
  296. }
  297. //************************************************************************************************************************
  298. //3.初始化地图,初始化了草地、作业、正常校门的位置数组,初始化了墙图(0不可以走,1是草地和空地,2是窗户)
  299. void initialmap(IAPI& api) {
  300. /*api.Print("initialmap called");*/
  301. auto map = api.GetFullMap();
  302. if (api.GetPlaceType(5, 6) == THUAI6::PlaceType::Gate)
  303. mapflag = 0;
  304. else
  305. mapflag = 1;
  306. if (1) {
  307. int i, j;
  308. for (i = 0; i < 50; i++)
  309. for (j = 0; j < 50; j++)
  310. {
  311. if (map[i][j] == THUAI6::PlaceType::Land || map[i][j] == THUAI6::PlaceType::Grass || map[i][j] == THUAI6::PlaceType::Door3 || map[i][j] == THUAI6::PlaceType::Door6 || map[i][j] == THUAI6::PlaceType::Door5) {
  312. wallmap[i][j] = 1;
  313. }
  314. else if (map[i][j] == THUAI6::PlaceType::Window) {
  315. wallmap[i][j] = 2;
  316. }
  317. else {
  318. wallmap[i][j] = 0;
  319. }
  320. if (map[i][j] == THUAI6::PlaceType::ClassRoom) {
  321. mapnode temp = { api.CellToGrid(i),api.CellToGrid(j) };
  322. homeworkmap.emplace_back(temp);
  323. /*for (int k = 0; k < 8; k++)
  324. if (map[i + d8x[k]][j + d8y[k]] == THUAI6::PlaceType::Grass || map[i + d8x[k]][j + d8y[k]] == THUAI6::PlaceType::Land) {
  325. mapnode temp1 = { i + d8x[k],j + d8y[k] };
  326. routemap.emplace_back(temp1);
  327. break;*/
  328. /*}*/
  329. }
  330. else if (map[i][j] == THUAI6::PlaceType::Grass) {
  331. mapnode temp = { api.CellToGrid(i),api.CellToGrid(j) };
  332. grassmap.emplace_back(temp);
  333. }
  334. else if (map[i][j] == THUAI6::PlaceType::Gate) {
  335. mapnode temp = { api.CellToGrid(i),api.CellToGrid(j) };
  336. xiaomenmap.emplace_back(temp);
  337. //for (int k = 0; k < 8; k++)
  338. // if (map[i + d8x[k]][j + d8y[k]] == THUAI6::PlaceType::Grass || map[i + d8x[k]][j + d8y[k]] == THUAI6::PlaceType::Land) {
  339. // mapnode temp1 = { i + d8x[k],j + d8y[k] };
  340. // routemap.emplace_back(temp1);
  341. // break;
  342. // }
  343. }
  344. }
  345. /*initialized = 1;*/
  346. }
  347. /*api.Print("initialmap eneded");*/
  348. }
  349. mapnode gridtonode(mapnode grid);
  350. //4.计算应该走的方向
  351. void Move(mapnode n1, mapnode n2)
  352. {
  353. if (n1.x > n2.x && n1.y == n2.y)direction = 1;
  354. if (n1.x > n2.x && n1.y > n2.y)direction = 2;
  355. if (n1.x == n2.x && n1.y > n2.y)direction = 3;
  356. if (n1.x < n2.x && n1.y > n2.y)direction = 4;
  357. if (n1.x < n2.x && n1.y == n2.y)direction = 5;
  358. if (n1.x < n2.x && n1.y < n2.y)direction = 6;
  359. if (n1.x == n2.x && n1.y < n2.y)direction = 7;
  360. if (n1.x > n2.x && n1.y < n2.y)direction = 8;
  361. }
  362. //5.计算哪个东西距离自己最近
  363. mapnode mindisgrid(mapnode nowgrid, std::vector<mapnode>& candidate) {
  364. int d = 2147483647, k = 0;
  365. for (int i = 0; i < candidate.size(); i++) {
  366. if (distant(nowgrid, candidate[i]) < d) {
  367. d = distant(nowgrid, candidate[i]);
  368. k = i;
  369. }
  370. }
  371. mapnode temp = candidate[k];
  372. return temp;
  373. }
  374. //作业专用
  375. mapnode mindisgrid(mapnode nowgrid, std::vector<mapnode>& candidate, IStudentAPI& api) {
  376. int d = 2147483647, k = 0;
  377. for (int i = 0; i < 10; i++) {
  378. //api.Print(fmt::format("{}", juanedmap[i]));
  379. if ((distant(nowgrid, candidate[i]) < d)&&!juanedmap[i]) {
  380. d = distant(nowgrid, candidate[i]);
  381. k = i;
  382. }
  383. }
  384. mapnode temp = candidate[k];
  385. /*api.Print("sssend");*/
  386. return temp;
  387. }
  388. //6.坐标转换
  389. mapnode gridtonode(mapnode grid) {
  390. mapnode temp;
  391. temp.x = grid.x / 1000;
  392. temp.y = grid.y / 1000;
  393. return temp;
  394. }
  395. mapnode nodetogrid(mapnode node) {
  396. mapnode temp;
  397. temp.x = node.x * 1000 + 500;
  398. temp.y = node.y * 1000 + 500;
  399. return temp;
  400. }
  401. //7.站位计算
  402. static int dx[4] = { 1,0,-1,0 };
  403. static int dy[4] = { 0,-1,0,1 };
  404. mapnode poscal(IAPI& api, mapnode node) {
  405. std::vector<mapnode> temp;
  406. for (int i = 0; i < 4; i++) {
  407. if (wallmap[node.x + dx[i]][node.y + dy[i]]!=0) {
  408. mapnode node1;
  409. node1 = { (node.x + dx[i]),(node.y + dy[i]) };
  410. temp.emplace_back(node1);
  411. break;
  412. }
  413. }
  414. return temp[0];
  415. }
  416. //8.查找点是否在其中
  417. bool findin(std::vector<mapnode>path, mapnode node) {
  418. for (int i = 0; i < path.size(); i++) {
  419. if (path[i].x == node.x && path[i].y == node.y)
  420. return 1;
  421. }
  422. return 0;
  423. }
  424. //*************************************************************************************************************************
  425. //基本状态,封装了走路函数
  426. class basicstate
  427. {
  428. public:
  429. virtual void statemove(IStudentAPI& api);
  430. virtual void statetransfer(IStudentAPI& api);
  431. info nowinfo;
  432. basicstate(IStudentAPI& api);
  433. virtual ~basicstate();
  434. void walkpath(IStudentAPI& api);
  435. int isarrive(IStudentAPI& api);
  436. bool isskipwindow();
  437. void skipwindow(IStudentAPI& api);
  438. bool isarrivend(IStudentAPI& api);
  439. void walkcomp(IStudentAPI& api, mapnode grid);
  440. virtual void print(IStudentAPI& api) {
  441. //api.Print(":aa");
  442. }
  443. mapnode tonode;
  444. bool stuck;
  445. };
  446. //每次play更新信息
  447. basicstate::basicstate(IStudentAPI& api) {
  448. //api.Print("initself called");
  449. auto self = api.GetSelfInfo();
  450. nowinfo.nownode.x = api.GridToCell(self->x);
  451. nowinfo.nownode.y = api.GridToCell(self->y);
  452. nowinfo.nowgrid.x = self->x;
  453. nowinfo.nowgrid.y = self->y;
  454. if (distant(nowinfo.nowgrid, lastgrid) < 0.1)
  455. stuck = 1;
  456. else
  457. stuck = 0;
  458. lastgrid.x = self->x;
  459. lastgrid.y = self->y;
  460. for (int i = 0; i < 3; i++) {
  461. nowinfo.CD[i] = self->timeUntilSkillAvailable[i];
  462. }
  463. nowinfo.dangeralert = self->dangerAlert;
  464. nowinfo.trickerinfo = api.GetTrickers();
  465. auto belf = api.GetStudents();
  466. //api.Print(fmt::format("{}", belf.size()));
  467. int j=0;
  468. if (self->studentType == THUAI6::StudentType::StraightAStudent) {
  469. for (int i = 0; i < 4; i++) {
  470. if (belf[i]->playerID != self->playerID) {
  471. mapnode tt = gridtonode({ belf[i]->x, belf[i]->y });
  472. wallmap[tt.x][tt.y] = 0;
  473. if (belf[i]->studentType == THUAI6::StudentType::Teacher)
  474. for (int i = 0; i < 8; i++) {
  475. mapnode temp = { tt.x + d8x[i],tt.y + d8y[i] };
  476. if (temp.x >= 0 || temp.x < 50 || temp.y >= 0 || temp.y < 50)
  477. wallmap[temp.x][temp.y] = 0;
  478. }
  479. }
  480. if (!nowinfo.trickerinfo.empty()) {
  481. mapnode tt = gridtonode({ nowinfo.trickerinfo[0]->x, nowinfo.trickerinfo[0]->y });
  482. wallmap[tt.x][tt.y] = 0;
  483. }
  484. }
  485. if (api.HaveMessage()) {
  486. auto message=api.GetMessage().second;
  487. std::string nodex;
  488. std::string nodey;
  489. int i = 0;
  490. auto f = message.find(',');
  491. nodex = message.substr(0, f);
  492. int xx = atoi(nodex.c_str());
  493. auto l = message.size();
  494. nodey = message.substr(f + 1, l - f - 1);
  495. int yy = atoi(nodey.c_str());
  496. xx = api.CellToGrid(xx);
  497. yy = api.CellToGrid(yy);
  498. int s;
  499. for ( s = 0; s < 10; s++)
  500. if (homeworkmap[s].x == xx && homeworkmap[s].y == yy)
  501. break;
  502. juanedmap[s] = 1;
  503. }
  504. if (!api.GetTrickers().empty()) {
  505. mapnode node = { api.GridToCell(api.GetTrickers()[0]->x),api.GridToCell(api.GetTrickers()[0]->y) };
  506. api.SendTextMessage(0, fmt::format("{},{}", node.x, node.y));
  507. api.SendTextMessage(2, fmt::format("{},{}", node.x, node.y));
  508. }
  509. }
  510. //for (int m = 0; m < 10; m++)
  511. // api.Print(fmt::format("{}", juanedmap[m]));
  512. }
  513. //学生好像需要记忆
  514. basicstate::~basicstate() {
  515. lastpos = tonode;
  516. }
  517. //沿路径走
  518. //判断是否到达目标并且改变方向和迭代器
  519. int basicstate::isarrive(IStudentAPI& api) {
  520. //api.Print(fmt::format("{},{}", path[counter].x, path[counter].y));
  521. if (path.empty())
  522. return 0;
  523. else if (distant(nowinfo.nowgrid, nodetogrid(path[counter])) <= 100) {
  524. /*double angle = atan2((path[counter].y - nowinfo.nowgrid.y), (path[counter].x - nowinfo.nowgrid.x));
  525. int time = distant(nowinfo.nowgrid, nodetogrid(path[counter])) * 1000 / Constants::Sunshine::moveSpeed;
  526. api.Move(time,angle).get();*/
  527. //api.Print("arrivedpoint");
  528. Move(path[counter], path[counter + 1]);
  529. counter++;
  530. //api.Print(fmt::format("{}", counter));
  531. return 1;
  532. }
  533. //else if (distant(nowinfo.nowgrid, nodetogrid(path[counter])) >= 2000) {
  534. // /*api.Print("pianli called");
  535. // unlockAstar = 1;
  536. // unlockpos = 1;
  537. // return 2;*/
  538. //}
  539. else return 0;
  540. }
  541. //还是得位置补偿。。。
  542. void basicstate::walkcomp(IStudentAPI& api, mapnode grid) {
  543. //api.Print("walkcomp called");
  544. double angle = atan2((grid.y - nowinfo.nowgrid.y), (grid.x - nowinfo.nowgrid.x));
  545. int time;
  546. if (api.GetSelfInfo()->studentType == THUAI6::StudentType::Teacher) {
  547. time = distant(grid, nowinfo.nowgrid) * 1000 / 2700;
  548. }
  549. else {
  550. time = distant(grid, nowinfo.nowgrid) * 1000 / 2880;
  551. }
  552. //api.Print(fmt::format("{},{}", nowinfo.nowgrid.y, nowinfo.nowgrid.x));
  553. //api.Print(fmt::format("time{}", time));
  554. /* api.Move(time, angle);
  555. if (time < 200) {
  556. std::this_thread::sleep_for(std::chrono::milliseconds(time));
  557. }
  558. else {
  559. std::this_thread::sleep_for(std::chrono::milliseconds(200));
  560. api.EndAllAction();
  561. }*/
  562. }
  563. //判断是否到达终点
  564. bool basicstate::isarrivend(IStudentAPI& api) {
  565. if (distant(nodetogrid(tonode), nowinfo.nowgrid) <= 100) {
  566. //api.Print("arrived");
  567. walkcomp(api, nodetogrid(tonode));
  568. counter = 0;
  569. return 1;
  570. }
  571. else if (path.empty()) {
  572. return 0;
  573. }
  574. else {
  575. if (distant(nowinfo.nowgrid, { api.CellToGrid(path[counter].x),api.CellToGrid(path[counter].y) }) <= 100 && counter == (path.size() - 1)) {
  576. //api.Print("arrived pathend");
  577. walkcomp(api, nodetogrid(path.back()));
  578. counter = 0;
  579. return 1;
  580. }
  581. else return 0;
  582. }
  583. }
  584. //判断是否需要进行翻窗
  585. bool basicstate::isskipwindow()
  586. {
  587. if (wallmap[path[counter].x][path[counter].y] == 2)
  588. return true;
  589. else
  590. return 0;
  591. }
  592. //进行翻窗并改变迭代器
  593. void basicstate::skipwindow(IStudentAPI& api) {
  594. if (api.SkipWindow().get()) {
  595. counter++;
  596. }
  597. }
  598. //根据方向执行走路命令
  599. void basicstate::walkpath(IStudentAPI& api) {
  600. if (api.GetSelfInfo()->studentType == THUAI6::StudentType::Teacher) {
  601. if (direction == 1) {
  602. //api.EndAllAction();
  603. api.MoveUp(92);
  604. std::this_thread::sleep_for(std::chrono::milliseconds(102));
  605. }
  606. if (direction == 2) {
  607. //api.EndAllAction();
  608. api.Move(131, P2I * 5);
  609. std::this_thread::sleep_for(std::chrono::milliseconds(141));
  610. }
  611. if (direction == 3) {
  612. //api.EndAllAction();
  613. api.MoveLeft(92);
  614. std::this_thread::sleep_for(std::chrono::milliseconds(102));
  615. }
  616. if (direction == 4) {
  617. /*api.EndAllAction(); */
  618. api.Move(131, P2I * 7);
  619. std::this_thread::sleep_for(std::chrono::milliseconds(141));
  620. }
  621. if (direction == 5) {
  622. /* api.EndAllAction(); */
  623. api.MoveDown(92);
  624. std::this_thread::sleep_for(std::chrono::milliseconds(102));
  625. }
  626. if (direction == 6) {
  627. //api.EndAllAction();
  628. api.Move(131, P2I);
  629. std::this_thread::sleep_for(std::chrono::milliseconds(141));
  630. }
  631. if (direction == 7) {
  632. //api.EndAllAction();
  633. api.MoveRight(92);
  634. std::this_thread::sleep_for(std::chrono::milliseconds(102));
  635. }
  636. if (direction == 8) {
  637. //api.EndAllAction();
  638. api.Move(131, P2I * 3);
  639. std::this_thread::sleep_for(std::chrono::milliseconds(141));
  640. }
  641. }
  642. //api.Print(fmt::format("{}", direction));
  643. //api.Print(fmt::format("{}", counter));
  644. //api.Print("walkpath used!");
  645. else {
  646. if (direction == 1) {
  647. //api.EndAllAction();
  648. api.MoveUp(87);
  649. std::this_thread::sleep_for(std::chrono::milliseconds(97));
  650. }
  651. if (direction == 2) {
  652. //api.EndAllAction();
  653. api.Move(123, P2I * 5);
  654. std::this_thread::sleep_for(std::chrono::milliseconds(133));
  655. }
  656. if (direction == 3) {
  657. //api.EndAllAction();
  658. api.MoveLeft(87);
  659. std::this_thread::sleep_for(std::chrono::milliseconds(97));
  660. }
  661. if (direction == 4) {
  662. /*api.EndAllAction(); */
  663. api.Move(123, P2I * 7);
  664. std::this_thread::sleep_for(std::chrono::milliseconds(133));
  665. }
  666. if (direction == 5) {
  667. /* api.EndAllAction(); */
  668. api.MoveDown(87);
  669. std::this_thread::sleep_for(std::chrono::milliseconds(97));
  670. }
  671. if (direction == 6) {
  672. //api.EndAllAction();
  673. api.Move(123, P2I);
  674. std::this_thread::sleep_for(std::chrono::milliseconds(133));
  675. }
  676. if (direction == 7) {
  677. //api.EndAllAction();
  678. api.MoveRight(87);
  679. std::this_thread::sleep_for(std::chrono::milliseconds(97));
  680. }
  681. if (direction == 8) {
  682. //api.EndAllAction();
  683. api.Move(123, P2I * 3);
  684. std::this_thread::sleep_for(std::chrono::milliseconds(133));
  685. }
  686. }
  687. }
  688. //用于测试走路代码的,没啥用
  689. static bool test = 1;
  690. void basicstate::statemove(IStudentAPI& api) {
  691. /*if (unlockAstar) {
  692. pathmerging(nowinfo.nownode, { 19,15 }, path, api);
  693. for (int i = 0; i < path.size(); i++)
  694. api.Print(fmt::format("{},{}\n", path[i].x, path[i].y));
  695. unlockAstar = 0;
  696. }
  697. if (isarrivend(api)) { std::this_thread::sleep_for(std::chrono::seconds(100)); }
  698. else {
  699. isarrive(api);
  700. if (!isskipwindow()) {
  701. walkpath(api);
  702. }
  703. else {
  704. skipwindow(api);
  705. }
  706. }*/
  707. }
  708. void basicstate::statetransfer(IStudentAPI& api) {
  709. ;
  710. }
  711. //*************************************************************************************************************************
  712. static std::vector < mapnode> initnode1 = { { 21,25 }, {15,40},{40,30},{25,10} };
  713. static std::vector < mapnode> initnode2 = { {20,20}, {30,20} ,{30,35},{20,35} };
  714. static mapnode meg;
  715. static int routecounte = 0;
  716. //状态四,初始行动
  717. class initmove :public basicstate {
  718. public:
  719. virtual ~initmove() { ; }
  720. initmove(IStudentAPI& api) :basicstate(api) { ; }
  721. virtual void statemove(IStudentAPI& api);
  722. virtual void statetransfer(IStudentAPI& api);
  723. virtual void print(IStudentAPI& api) {
  724. //api.Print("sssaa");
  725. }
  726. bool getmes(IStudentAPI& api);
  727. };
  728. bool initmove::getmes(IStudentAPI& api) {
  729. if (api.HaveMessage()) {
  730. auto a = api.GetMessage();
  731. a.second;
  732. std::string nodex;
  733. std::string nodey;
  734. int i = 0;
  735. auto f = a.second.find(',');
  736. nodex = a.second.substr(0, f);
  737. //api.Print(nodex);
  738. int xx = atoi(nodex.c_str());
  739. //api.Print(fmt::format("{}", xx));
  740. auto l = a.second.size();
  741. nodey = a.second.substr(f + 1, l - f - 1);
  742. //api.Print(nodey);
  743. int yy = atoi(nodey.c_str());
  744. meg = { xx,yy };
  745. return true;
  746. }
  747. else
  748. return false;
  749. }
  750. void initmove::statemove(IStudentAPI& api) {
  751. //api.Print("aaaaaaa");
  752. if(mapflag==0)
  753. tonode = initnode1[routecounte];
  754. else
  755. tonode= initnode2[routecounte];
  756. if (unlockAstar == 1) {
  757. pathmerging(nowinfo.nownode, tonode, path, api);
  758. //api.Print(fmt::format("{}\n", path.size()));
  759. //for (int i = 0; i < path.size(); i++)
  760. // api.Print(fmt::format("{},{}\n", path[i].x, path[i].y));
  761. unlockAstar = 0;
  762. }
  763. if (!path.empty()) {
  764. if (!isarrivend(api)) {
  765. if (isarrive(api)) {
  766. walkcomp(api, nodetogrid(path[counter - 1]));
  767. }
  768. //else if (flag == 2) {
  769. // ;
  770. {
  771. if (!isskipwindow()) {
  772. walkpath(api);
  773. }
  774. else {
  775. skipwindow(api);
  776. }
  777. }
  778. }
  779. else {
  780. walkcomp(api, nodetogrid(tonode));
  781. unlockAstar = 1;
  782. routecounte++;
  783. if (mapflag == 0)
  784. routecounte %= initnode1.size();
  785. else
  786. routecounte %= initnode2.size();
  787. }
  788. }
  789. }
  790. void initmove::statetransfer(IStudentAPI& api) {
  791. //api.Print(fmt::format("{}", api.GetTrickers().empty()));
  792. if (stuck) {
  793. curstate = 4;
  794. }
  795. else if (getmes(api)) {
  796. unlockAstar = 1;
  797. curstate = 7;
  798. }
  799. else if (!api.GetTrickers().empty()) {
  800. unlockAstar = 1;
  801. curstate = 5;
  802. }
  803. }
  804. //*************************************************************************************************************************
  805. int zone(mapnode self, mapnode target);
  806. //状态五,卡人,初步接近
  807. class lesson :public basicstate {
  808. public:
  809. virtual ~lesson() { ; }
  810. lesson(IStudentAPI& api) :basicstate(api) { ; }
  811. virtual void statemove(IStudentAPI& api);
  812. virtual void statetransfer(IStudentAPI& api);
  813. void infosend(IStudentAPI& api);
  814. void roughpos(IStudentAPI& api);
  815. };
  816. void lesson::infosend(IStudentAPI& api) {
  817. if (!nowinfo.trickerinfo.empty()) {
  818. auto a = (zone(nowinfo.nowgrid, { nowinfo.trickerinfo[0]->x,nowinfo.trickerinfo[0]->y }) + 2) % 4;
  819. //api.Print(fmt::format("{},{}", a, zone(nowinfo.nowgrid, { nowinfo.trickerinfo[0]->x,nowinfo.trickerinfo[0]->y })));
  820. int x = nowinfo.trickerinfo[0]->x / 1000;
  821. int y = nowinfo.trickerinfo[0]->y / 1000;
  822. /*switch (a) {
  823. case(1): {
  824. x = x - 1;
  825. y = y - 1;
  826. break;
  827. }
  828. case(2): {
  829. x += 1;
  830. y -= 1;
  831. break;
  832. }
  833. case(3): {
  834. x += 1;
  835. y += 1;
  836. break;
  837. }
  838. case(4): {
  839. x -= 1;
  840. y += 1;
  841. break;
  842. }
  843. }*/
  844. if (api.GetSelfInfo()->playerID == 2)
  845. api.SendBinaryMessage(0, fmt::format("{},{}", x, y));
  846. else if (api.GetSelfInfo()->playerID == 0)
  847. api.SendBinaryMessage(2, fmt::format("{},{}", x, y));
  848. }
  849. }
  850. void lesson::roughpos(IStudentAPI& api) {
  851. if (!nowinfo.trickerinfo.empty()) {
  852. int d = 100000000;
  853. int j;
  854. mapnode g;
  855. for (int i = 1; i < 8; i = i + 2) {
  856. auto place = api.GetPlaceType(api.GridToCell(nowinfo.trickerinfo[0]->x), api.GridToCell(nowinfo.trickerinfo[0]->y));
  857. if (place == THUAI6::PlaceType::Grass || place == THUAI6::PlaceType::Land) {
  858. mapnode aaa = gridtonode({ nowinfo.trickerinfo[0]->x, nowinfo.trickerinfo[0]->y });
  859. aaa.x += d8x[i];
  860. aaa.y += d8y[i];
  861. int temp = distant(nowinfo.nowgrid, nodetogrid(aaa));
  862. if (temp < d)
  863. {
  864. d = temp;
  865. g.x = aaa.x;
  866. g.y = aaa.y;
  867. }
  868. }
  869. }
  870. if (g.x != lastpos.x && g.y != lastpos.y) {
  871. tonode = g;
  872. unlockAstar = 1;
  873. }
  874. }
  875. }
  876. void lesson::statemove(IStudentAPI& api) {
  877. //roughpos(api);
  878. mapnode temp = gridtonode({ nowinfo.trickerinfo[0]->x,nowinfo.trickerinfo[0]->y });
  879. if (lastpos.x != temp.x && lastpos.y != temp.y) {
  880. tonode = temp;
  881. unlockAstar = 1;
  882. }
  883. infosend(api);
  884. //api.Print("bnbbbb");
  885. if (unlockAstar == 1) {
  886. pathmerging(nowinfo.nownode, tonode, path, api);
  887. if (!path.empty()) {
  888. //api.Print(fmt::format("{}\n", path.size()));
  889. //for (int i = 0; i < path.size(); i++)
  890. // api.Print(fmt::format("{},{}\n", path[i].x, path[i].y));
  891. }
  892. unlockAstar = 0;
  893. }
  894. if (!path.empty()) {
  895. if (!isarrivend(api)) {
  896. if (isarrive(api)) {
  897. walkcomp(api, nodetogrid(path[counter - 1]));
  898. }
  899. //else if (flag == 2) {
  900. // ;
  901. {
  902. if (!isskipwindow()) {
  903. walkpath(api);
  904. }
  905. else {
  906. skipwindow(api);
  907. }
  908. }
  909. }
  910. else {
  911. walkcomp(api, nodetogrid(tonode));
  912. unlockAstar = 1;
  913. }
  914. }
  915. }
  916. void lesson::statetransfer(IStudentAPI& api) {
  917. if (stuck)
  918. curstate = 9;
  919. else if (nowinfo.trickerinfo.empty()) {
  920. curstate = 4;
  921. }
  922. else if ((distant(nowinfo.nowgrid, {nowinfo.trickerinfo[0]->x, nowinfo.trickerinfo[0]->y}))<2100) {
  923. curstate = 6;
  924. }
  925. }
  926. //*************************************************************************************************************************
  927. int zone(mapnode self, mapnode target) {
  928. //一象限,以此类推
  929. if (self.x >= target.x && self.y > target.y)
  930. return 1;
  931. else if (self.x < target.x && self.y >= target.y)
  932. return 2;
  933. else if (self.x <= target.x && self.y < target.y)
  934. return 3;
  935. else if (self.x > target.x && self.y <= target.y)
  936. return 4;
  937. else
  938. return 5;
  939. }
  940. //状态六,卡人,接近微操
  941. class teach :public basicstate {
  942. public:
  943. virtual ~teach() { ; }
  944. teach(IStudentAPI& api) :basicstate(api) { ; }
  945. virtual void statemove(IStudentAPI& api);
  946. virtual void statetransfer(IStudentAPI& api);
  947. void sendinfo(IStudentAPI& api);
  948. bool poscheck(IStudentAPI& api);
  949. mapnode actpos();
  950. };
  951. bool teach::poscheck(IStudentAPI& api) {
  952. bool flag=1;
  953. for (int i = 0; i < 8; i++) {
  954. mapnode temp = { api.GridToCell(nowinfo.trickerinfo[0]->x)+d8x[i],api.GridToCell(nowinfo.trickerinfo[0]->y)+d8y[i]};
  955. if (api.GetPlaceType(temp.x, temp.y) == THUAI6::PlaceType::Land || api.GetPlaceType(temp.x, temp.y) == THUAI6::PlaceType::Grass)
  956. flag = flag;
  957. else
  958. flag = 0;
  959. }
  960. return flag;
  961. }
  962. mapnode teach::actpos() {
  963. auto zo = zone(nowinfo.nowgrid, { nowinfo.trickerinfo[0]->x, nowinfo.trickerinfo[0]->y });
  964. mapnode temp = { -1,-1 };
  965. switch (zo) {
  966. case(1): {
  967. temp = { nowinfo.trickerinfo[0]->x + 400,nowinfo.trickerinfo[0]->y + 700 };
  968. return temp;
  969. break;
  970. }
  971. case(2): {
  972. temp = { nowinfo.trickerinfo[0]->x -700,nowinfo.trickerinfo[0]->y + 400 };
  973. return temp;
  974. break;
  975. }
  976. case(3): {
  977. temp = { nowinfo.trickerinfo[0]->x -400,nowinfo.trickerinfo[0]->y -700 };
  978. return temp;
  979. break;
  980. }
  981. case(4): {
  982. temp = { nowinfo.trickerinfo[0]->x + 700,nowinfo.trickerinfo[0]->y -400 };
  983. return temp;
  984. break;
  985. }
  986. }
  987. return temp;
  988. }
  989. void teach::sendinfo(IStudentAPI& api) {
  990. if (!nowinfo.trickerinfo.empty()) {
  991. auto a = (zone(nowinfo.nowgrid, { nowinfo.trickerinfo[0]->x,nowinfo.trickerinfo[0]->y })) % 4;
  992. //api.Print(fmt::format("{},{}", a, zone(nowinfo.nowgrid, { nowinfo.trickerinfo[0]->x,nowinfo.trickerinfo[0]->y })));
  993. int x = nowinfo.trickerinfo[0]->x / 1000;
  994. int y = nowinfo.trickerinfo[0]->y / 1000;
  995. /*switch (a) {
  996. case(1): {
  997. x = x- 1;
  998. y = y - 1;
  999. break;
  1000. }
  1001. case(2): {
  1002. x+=1;
  1003. y-=1;
  1004. break;
  1005. }
  1006. case(3): {
  1007. x+=1;
  1008. y+=1;
  1009. break;
  1010. }
  1011. case(0): {
  1012. x-=1;
  1013. y+=1;
  1014. break;
  1015. }
  1016. }*/
  1017. if (api.GetSelfInfo()->playerID == 2)
  1018. api.SendBinaryMessage(0, fmt::format("{},{}", x, y));
  1019. else if (api.GetSelfInfo()->playerID == 0)
  1020. api.SendBinaryMessage(2, fmt::format("{},{}", x, y));
  1021. //}
  1022. }
  1023. }
  1024. void teach::statemove(IStudentAPI& api) {
  1025. if (api.GetSelfInfo()->playerID == 2) {
  1026. tonode = actpos();
  1027. sendinfo(api);
  1028. if (distant(nowinfo.nowgrid, tonode) > 1) {
  1029. double angle1 = -atan2((api.GetTrickers()[0]->y - api.GetSelfInfo()->y), (api.GetTrickers()[0]->x - api.GetSelfInfo()->x));
  1030. int time1 = 20;
  1031. api.EndAllAction();
  1032. auto b = api.Move(time1, angle1).get();
  1033. api.Wait();
  1034. double angle = atan2((tonode.y - api.GetSelfInfo()->y), (tonode.x - api.GetSelfInfo()->x));
  1035. int time = distant(tonode, { api.GetSelfInfo()->x ,api.GetSelfInfo()->y }) * 1000 / 2700;
  1036. api.EndAllAction();
  1037. auto a = api.Move(time, angle).get();
  1038. }
  1039. if (nowinfo.CD[0] < 0.1)
  1040. if (nowinfo.trickerinfo[0]->playerState == THUAI6::PlayerState::Attacking || nowinfo.trickerinfo[0]->playerState == THUAI6::PlayerState::Swinging)
  1041. api.UseSkill(0).get();
  1042. }
  1043. else {
  1044. std::shared_ptr<const THUAI6::Student> mate;
  1045. for (int i = 0; i < 4; i++) {
  1046. if (api.GetStudents()[i]->playerID == 2)
  1047. mate = api.GetStudents()[i];
  1048. }
  1049. sendinfo(api);
  1050. auto b=zone({ mate->x,mate->y }, { nowinfo.trickerinfo[0]->x, nowinfo.trickerinfo[0]->y });
  1051. int a = (b + 2) % 4;
  1052. switch (a) {
  1053. case(1): {
  1054. tonode = { nowinfo.trickerinfo[0]->x + 400,nowinfo.trickerinfo[0]->y + 700 };
  1055. break;
  1056. }
  1057. case(2): {
  1058. tonode = { nowinfo.trickerinfo[0]->x - 700,nowinfo.trickerinfo[0]->y + 400 };
  1059. break;
  1060. }
  1061. case(3): {
  1062. tonode = { nowinfo.trickerinfo[0]->x - 400,nowinfo.trickerinfo[0]->y - 700 };
  1063. break;
  1064. }
  1065. case(0): {
  1066. tonode = { nowinfo.trickerinfo[0]->x + 700,nowinfo.trickerinfo[0]->y - 400 };
  1067. break;
  1068. }
  1069. }
  1070. /*if(!(api.GetPlaceType(tonode.x/1000, tonode.y / 1000)==THUAI6::PlaceType::Grass|| api.GetPlaceType(tonode.x / 1000, tonode.y / 1000) == THUAI6::PlaceType::Land))
  1071. for (int i = 0; i < 4; i++) {
  1072. if (b != i) {
  1073. tonode = { nowinfo.trickerinfo[0]->x + d30x[i],nowinfo.trickerinfo[0]->y + d30y[i] };
  1074. if (api.GetPlaceType(tonode.x / 1000, tonode.y / 1000) == THUAI6::PlaceType::Grass || api.GetPlaceType(tonode.x / 1000, tonode.y / 1000) == THUAI6::PlaceType::Land)
  1075. break;
  1076. }
  1077. }*/
  1078. if (distant(nowinfo.nowgrid, tonode) > 20) {
  1079. double angle1 = -atan2((api.GetTrickers()[0]->y - api.GetSelfInfo()->y), (api.GetTrickers()[0]->x - api.GetSelfInfo()->x));
  1080. int time1 = 20;
  1081. auto b = api.Move(time1, angle1);
  1082. std::this_thread::sleep_for(std::chrono::milliseconds(20));
  1083. double angle = atan2((tonode.y - api.GetSelfInfo()->y), (tonode.x - api.GetSelfInfo()->x));
  1084. int time = distant(tonode, { api.GetSelfInfo()->x ,api.GetSelfInfo()->y }) * 1000 / 2700;
  1085. auto a = api.Move(time, angle);
  1086. std::this_thread::sleep_for(std::chrono::milliseconds(time));
  1087. }
  1088. if (nowinfo.CD[0] < 0.1)
  1089. if (nowinfo.trickerinfo[0]->playerState == THUAI6::PlayerState::Attacking || nowinfo.trickerinfo[0]->playerState == THUAI6::PlayerState::Swinging)
  1090. api.UseSkill(0).get();
  1091. }
  1092. }
  1093. void teach::statetransfer(IStudentAPI& api) {
  1094. if (api.GetTrickers().empty())
  1095. curstate = 4;
  1096. /*else if(poscheck(api))
  1097. curstate = 4;*/
  1098. else if (distant(nowinfo.nowgrid, { nowinfo.trickerinfo[0]->x,nowinfo.trickerinfo[0]->y }) > 3000)
  1099. curstate = 5;
  1100. }
  1101. //*************************************************************************************************************************
  1102. //状态七,收信息行动
  1103. class wego:public basicstate {
  1104. public:
  1105. virtual ~wego() { ; }
  1106. wego(IStudentAPI& api) :basicstate(api) { ; }
  1107. virtual void statemove(IStudentAPI& api);
  1108. virtual void statetransfer(IStudentAPI& api);
  1109. bool getmes(IStudentAPI& api);
  1110. };
  1111. bool wego::getmes(IStudentAPI& api) {
  1112. if (api.HaveMessage()) {
  1113. auto a = api.GetMessage();
  1114. a.second;
  1115. std::string nodex;
  1116. std::string nodey;
  1117. int i = 0;
  1118. auto f = a.second.find(',');
  1119. nodex = a.second.substr(0, f);
  1120. //api.Print(nodex);
  1121. int xx = atoi(nodex.c_str());
  1122. //api.Print(fmt::format("{}", xx));
  1123. auto l = a.second.size();
  1124. nodey = a.second.substr(f + 1, l - f - 1);
  1125. //api.Print(nodey);
  1126. int yy = atoi(nodey.c_str());
  1127. if (meg.x != xx || meg.y != yy) {
  1128. meg.x = xx;
  1129. meg.y = yy;
  1130. unlockAstar = 1;
  1131. }
  1132. return true;
  1133. }
  1134. else
  1135. return false;
  1136. }
  1137. void wego::statemove(IStudentAPI& api) {
  1138. getmes(api);
  1139. tonode = meg;
  1140. //if (stuck)
  1141. //{
  1142. // api.Print("struck");
  1143. // unlockAstar = 1;
  1144. // walkcomp(api, nodetogrid(nowinfo.nownode));
  1145. //
  1146. //}
  1147. //api.Print(fmt::format("{},{},{}", tonode.x, tonode.y, nowinfo.trickerinfo.empty()));
  1148. //if (!api.GetTrickers().empty()) {
  1149. // int x = api.GridToCell(nowinfo.trickerinfo[0]->x);
  1150. // int y = api.GridToCell(nowinfo.trickerinfo[0]->y);
  1151. // wallmap [x][y] = 0;
  1152. // unlockAstar == 1;
  1153. //}
  1154. if (unlockAstar == 1) {
  1155. pathmerging(nowinfo.nownode, tonode, path, api);
  1156. //api.Print(fmt::format("{}\n", path.size()));
  1157. //for (int i = 0; i < path.size(); i++)
  1158. // api.Print(fmt::format("{},{}\n", path[i].x, path[i].y));
  1159. unlockAstar = 0;
  1160. }
  1161. /*api.Print(fmt::format("{},{}", path[counter].x, path[counter].y));*/
  1162. if (!path.empty()) {
  1163. if (!isarrivend(api)) {
  1164. if (isarrive(api)) {
  1165. walkcomp(api, nodetogrid(path[counter - 1]));
  1166. }
  1167. {
  1168. if (!isskipwindow()) {
  1169. walkpath(api);
  1170. }
  1171. else {
  1172. skipwindow(api);
  1173. }
  1174. }
  1175. }
  1176. else {
  1177. walkcomp(api, nodetogrid(tonode));
  1178. unlockAstar = 1;
  1179. }
  1180. }
  1181. }
  1182. void wego::statetransfer(IStudentAPI& api) {
  1183. if (stuck)
  1184. curstate = 9;
  1185. /*else if (!nowinfo.trickerinfo.empty())
  1186. curstate = 5;*/
  1187. else if (!nowinfo.trickerinfo.empty()) {
  1188. if (distant(nowinfo.nowgrid, { nowinfo.trickerinfo[0]->x,nowinfo.trickerinfo[0]->y }) < 2100) {
  1189. /*api.Print(fmt::format("{},{},{},{}", nowinfo.nowgrid.x, nowinfo.nowgrid.y, nodetogrid(tonode).x, nodetogrid(tonode).y));*/
  1190. curstate = 6;
  1191. }
  1192. }
  1193. }
  1194. //*************************************************************************************************************************
  1195. static bool insave = 0;
  1196. //状态九卡住重动
  1197. class retry :public basicstate {
  1198. public:
  1199. virtual void statemove(IStudentAPI& api);
  1200. virtual void statetransfer(IStudentAPI& api);
  1201. retry(IStudentAPI& api) :basicstate(api) { ; }
  1202. virtual ~retry() { ; }
  1203. };
  1204. void retry::statemove(IStudentAPI& api) {
  1205. //mapnode temp;
  1206. //unlockAstar = 1;
  1207. //for(int i=0;i<8;i++)
  1208. // if (wallmap[nowinfo.nownode.x + d8x[i]][nowinfo.nownode.y + d8y[i]]!=0){
  1209. // temp = { nowinfo.nownode.x + d8x[i], nowinfo.nownode.y + d8y[i] };
  1210. // }
  1211. unlockAstar = 1;
  1212. api.Wait();
  1213. mapnode temp = { api.GetSelfInfo()->x,api.GetSelfInfo()->y };
  1214. mapnode to = nodetogrid(gridtonode(temp));
  1215. double angle = atan2(to.y - temp.y, to.x - temp.x);
  1216. int time;
  1217. if (api.GetSelfInfo()->studentType == THUAI6::StudentType::StraightAStudent)
  1218. time = distant(temp, to) * 1000 / 2880;
  1219. else
  1220. time = distant(temp, to) * 1000 / 2700;
  1221. api.Move(time, angle).get();
  1222. }
  1223. void retry::statetransfer(IStudentAPI& api) {
  1224. /*if (!stuck||distant(nowinfo.nowgrid,nodetogrid(nowinfo.nownode))<10)*/
  1225. if (api.GetSelfInfo()->studentType == THUAI6::StudentType::StraightAStudent) {
  1226. bool flag = 1;
  1227. for (int i = 0; i < 10; i++) {
  1228. if (juanedmap[i]==false) {
  1229. flag = 0;
  1230. break;
  1231. }
  1232. }
  1233. if(insave)
  1234. scurstate = 10;
  1235. else if(flag)
  1236. scurstate = 2;
  1237. else
  1238. scurstate = 3;
  1239. }
  1240. else
  1241. curstate = 4;
  1242. }
  1243. //*************************************************************************************************************************
  1244. //teacher完全体
  1245. class teacherall {
  1246. public:
  1247. virtual void statemove(IStudentAPI& api);
  1248. virtual void statetransfer(IStudentAPI& api);
  1249. teacherall(IStudentAPI& api);
  1250. virtual ~teacherall();
  1251. basicstate* nowstate;
  1252. };
  1253. teacherall::~teacherall() {
  1254. delete (nowstate);
  1255. }
  1256. teacherall ::teacherall(IStudentAPI& api) {
  1257. switch (curstate) {
  1258. case 4: {nowstate = new initmove(api);
  1259. //api.Print("now initmove");
  1260. break; }
  1261. case 5: {nowstate = new lesson(api);
  1262. /*api.Print("now lesson");*/
  1263. break; }
  1264. case 6: {nowstate = new teach(api);
  1265. /* api.Print("now teach");*/
  1266. break;}
  1267. case 7: {nowstate = new wego(api);
  1268. /*api.Print("now wego");*/
  1269. break; }
  1270. case 9: {nowstate = new retry(api);
  1271. /*api.Print("now retry");*/
  1272. break; }
  1273. }
  1274. }
  1275. void teacherall::statemove(IStudentAPI& api) {
  1276. //api.Print(fmt::format("now statemove"));
  1277. //nowstate->print(api);
  1278. nowstate->statemove(api);
  1279. }
  1280. void teacherall::statetransfer(IStudentAPI& api) {
  1281. auto a = curstate;
  1282. nowstate->statetransfer(api);
  1283. if (a == curstate) {
  1284. ;
  1285. }
  1286. else {
  1287. delete(nowstate);
  1288. switch (curstate) {
  1289. case 4: {nowstate = new initmove(api);
  1290. //nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));
  1291. /* api.Print("now transto initmove"); */
  1292. break; }
  1293. case 5: {nowstate = new lesson(api);
  1294. //nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));
  1295. /* api.Print("now transto lesson"); */
  1296. break; }
  1297. case 6: {nowstate = new teach(api);
  1298. /*nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));*/
  1299. /* api.Print("now transto teach");*/
  1300. break; }
  1301. case 7: {nowstate = new wego(api);
  1302. /*nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));*/
  1303. /*api.Print("now transto wego");*/
  1304. break;}
  1305. case 9: {nowstate = new retry(api);
  1306. /*nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));*/
  1307. /* api.Print("now transto retry");*/
  1308. break; }
  1309. }
  1310. }
  1311. }
  1312. //*************************************************************************************************************************
  1313. //目前卷
  1314. static mapnode nowjuan;
  1315. // 状态一,写作业
  1316. class juan :virtual public basicstate {
  1317. public:
  1318. virtual void statemove(IStudentAPI& api);
  1319. virtual void statetransfer(IStudentAPI& api);
  1320. juan(IStudentAPI& api) :basicstate(api) { ; }
  1321. virtual ~juan() { ; }
  1322. void startjuan(IStudentAPI& api);
  1323. bool juaned(IStudentAPI& api);
  1324. void initialnowjuan(IStudentAPI& api);
  1325. void useskill(IStudentAPI& api);
  1326. void findin();
  1327. bool tograduate(IStudentAPI& api);
  1328. void sendjuaned(IStudentAPI& api);
  1329. };
  1330. void juan::findin() {
  1331. auto temp = nodetogrid(nowjuan);
  1332. for (int i = 0; i < homeworkmap.size(); i++) {
  1333. if (nowjuan.x == homeworkmap[i].x && nowjuan.y == homeworkmap[i].y)
  1334. {
  1335. juanmap[i] = 1;
  1336. break;
  1337. }
  1338. }
  1339. }
  1340. void juan::useskill(IStudentAPI& api) {
  1341. if (nowinfo.CD[0] < 0.1)
  1342. api.UseSkill(0).get();
  1343. }
  1344. void juan::initialnowjuan(IStudentAPI& api) {
  1345. for (int i = 0; i < 8; i++) {
  1346. if (api.GetPlaceType(nowinfo.nownode.x + d8x[i], nowinfo.nownode.y + d8y[i]) == THUAI6::PlaceType::ClassRoom)
  1347. {
  1348. nowjuan = { nowinfo.nownode.x + d8x[i], nowinfo.nownode.y + d8y[i] };
  1349. break;
  1350. }
  1351. }
  1352. }
  1353. void juan::sendjuaned(IStudentAPI& api) {
  1354. if (api.GetSelfInfo()->playerID == 1)
  1355. api.SendTextMessage(3, fmt::format("{},{}", nowjuan.x, nowjuan.y));
  1356. if (api.GetSelfInfo()->playerID == 3)
  1357. api.SendTextMessage(1, fmt::format("{},{}", nowjuan.x, nowjuan.y));
  1358. }
  1359. bool juan::juaned(IStudentAPI& api) {
  1360. auto temp = api.GetClassroomProgress(nowjuan.x, nowjuan.y);
  1361. //api.Print(fmt::format("{}", abs(temp - 10000000)));
  1362. if (abs(temp - 10000000) < 1) {
  1363. int s;
  1364. for (s = 0; s < 10; s++)
  1365. if (homeworkmap[s].x ==api.CellToGrid(nowjuan.x) && homeworkmap[s].y == api.CellToGrid(nowjuan.y))
  1366. break;
  1367. juanedmap[s] = 1;
  1368. sendjuaned(api);
  1369. return 1;
  1370. }
  1371. else
  1372. return 0;
  1373. }
  1374. void juan::startjuan(IStudentAPI& api) {
  1375. api.StartLearning().get();
  1376. }
  1377. bool juan::tograduate(IStudentAPI& api) {
  1378. bool flag = 1;
  1379. for (int i = 0; i < 10; i++) {
  1380. if (juanedmap[i]==false) {
  1381. flag = 0;
  1382. break;
  1383. }
  1384. }
  1385. return flag;
  1386. }
  1387. void juan::statemove(IStudentAPI& api) {
  1388. initialnowjuan(api);
  1389. useskill(api);
  1390. if (api.GetSelfInfo()->playerState != THUAI6::PlayerState::Learning) {
  1391. startjuan(api);
  1392. }
  1393. }
  1394. void juan::statetransfer(IStudentAPI& api) {
  1395. if (tograduate(api)) {
  1396. scurstate = 2;
  1397. }
  1398. if (juaned(api)) {
  1399. /*findin();*/
  1400. scurstate = 3;
  1401. }
  1402. }
  1403. //*************************************************************************************************************************
  1404. static mapnode togradu = { -1,-1 };
  1405. //状态二,准备毕业
  1406. class readygraduate :virtual public basicstate {
  1407. public:
  1408. virtual void statemove(IStudentAPI& api);
  1409. virtual void statetransfer(IStudentAPI& api);
  1410. readygraduate(IStudentAPI& api) :basicstate(api) { ; }
  1411. virtual ~readygraduate() { ; }
  1412. };
  1413. void readygraduate::statemove(IStudentAPI& api) {
  1414. if (unlockAstar) {
  1415. auto temp = gridtonode(mindisgrid(nowinfo.nowgrid, xiaomenmap));
  1416. tonode = poscal(api, temp);
  1417. togradu = tonode;
  1418. pathmerging(nowinfo.nownode, tonode, path, api);
  1419. //api.Print(fmt::format("{},{},{},{},{}", nowinfo.nownode.x, nowinfo.nownode.y, tonode.x, tonode.y, path.size()));
  1420. //for (int i = 0; i < path.size(); i++)
  1421. // api.Print(fmt::format("{},{}\n", path[i].x, path[i].y));
  1422. unlockAstar = 0;
  1423. }
  1424. if (!path.empty()) {
  1425. if (!isarrivend(api)) {
  1426. if (isarrive(api)) {
  1427. walkcomp(api, nodetogrid(path[counter - 1]));
  1428. }
  1429. {
  1430. if (!isskipwindow()) {
  1431. walkpath(api);
  1432. }
  1433. else {
  1434. skipwindow(api);
  1435. }
  1436. }
  1437. }
  1438. else {
  1439. walkcomp(api, nodetogrid(tonode));
  1440. unlockAstar = 1;
  1441. }
  1442. }
  1443. }
  1444. void readygraduate::statetransfer(IStudentAPI& api) {
  1445. if (stuck) {
  1446. scurstate = 9;
  1447. }
  1448. if (distant(nowinfo.nowgrid, nodetogrid(togradu)) < 100) {
  1449. scurstate = 8;
  1450. }
  1451. }
  1452. //*************************************************************************************************************************
  1453. static mapnode tojuan = { -1,-1 };
  1454. //状态三,找作业
  1455. class gather :public virtual basicstate {
  1456. public:
  1457. virtual void statemove(IStudentAPI& api);
  1458. virtual void statetransfer(IStudentAPI& api);
  1459. void sendpos(IStudentAPI& api);
  1460. bool getinstru(IStudentAPI& api);
  1461. void getpos();
  1462. bool arrivejuan(IStudentAPI& api);
  1463. gather(IStudentAPI& api) :basicstate(api) { tonode = { -1,-1 }; }
  1464. bool tograduate(IStudentAPI& api);
  1465. };
  1466. //
  1467. bool gather::tograduate(IStudentAPI& api) {
  1468. bool flag = 1;
  1469. for (int i = 0; i < 10; i++) {
  1470. if (juanedmap[i]==false) {
  1471. flag = 0;
  1472. break;
  1473. }
  1474. }
  1475. return flag;
  1476. }
  1477. //判断是否到达卷点
  1478. bool gather::arrivejuan(IStudentAPI& api) {
  1479. for (int i = 0; i < 8; i++) {
  1480. if (api.GetPlaceType(nowinfo.nownode.x + d8x[i], nowinfo.nownode.y + d8y[i]) == THUAI6::PlaceType::ClassRoom)
  1481. return 1;
  1482. }
  1483. return 0;
  1484. }
  1485. //计算作业点
  1486. void gather::getpos() {
  1487. tonode = gridtonode(mindisgrid(nowinfo.nowgrid, homeworkmap));
  1488. }
  1489. //发送作业点
  1490. void gather::sendpos(IStudentAPI& api) {
  1491. std::string a;
  1492. a.append((char*)&tonode.x);
  1493. a.append((char*)&tonode.y);
  1494. for (int i = 0; i < 4; i++) {
  1495. if (i != api.GetSelfInfo()->playerID)
  1496. api.SendTextMessage(i, a);
  1497. }
  1498. }
  1499. //接受作业点
  1500. bool gather::getinstru(IStudentAPI& api) {
  1501. if (api.HaveMessage()) {
  1502. auto temp = api.GetMessage().second;
  1503. tonode.x = (int)temp[0];
  1504. tonode.y = (int)temp[1];
  1505. return true;
  1506. }
  1507. else
  1508. return false;
  1509. }
  1510. //找作业接口
  1511. void gather::statemove(IStudentAPI& api) {
  1512. //api.Print("1111");
  1513. //api.Print(fmt::format("{}",homeworkmap.size()));
  1514. //api.Print("2111");
  1515. //api.Print("3111");
  1516. auto temp = gridtonode(mindisgrid(nowinfo.nowgrid, homeworkmap, api));
  1517. auto temp2 = nodetogrid(temp);
  1518. tonode = poscal(api, temp);
  1519. tojuan = tonode;
  1520. if (lastpos.x != tonode.x || lastpos.y != tonode.y)
  1521. unlockAstar = 1;
  1522. if (unlockAstar) {
  1523. /*walkcomp(api, nodetogrid(nowinfo.nownode));*/
  1524. pathmerging(nowinfo.nownode, tonode, path, api);
  1525. //api.Print(fmt::format("{},{},{},{},{}", nowinfo.nownode.x, nowinfo.nownode.y, tonode.x, tonode.y, path.size()));
  1526. //for (int i = 0; i < path.size(); i++)
  1527. // api.Print(fmt::format("{},{}\n", path[i].x, path[i].y));
  1528. unlockAstar = 0;
  1529. }
  1530. if (!path.empty()) {
  1531. if (!isarrivend(api)) {
  1532. if (isarrive(api)) {
  1533. /*walkcomp(api, nodetogrid(path[counter - 1]));*/
  1534. ;
  1535. }
  1536. {
  1537. if (!isskipwindow()) {
  1538. walkpath(api);
  1539. }
  1540. else {
  1541. skipwindow(api);
  1542. }
  1543. }
  1544. }
  1545. else {
  1546. walkcomp(api, nodetogrid(tonode));
  1547. unlockAstar = 1;
  1548. }
  1549. }
  1550. }
  1551. //找作业转换
  1552. void gather::statetransfer(IStudentAPI& api) {
  1553. /*api.Print(fmt::format("{},{},{},{},{}", distant(nowinfo.nowgrid, nodetogrid(tonode)), nowinfo.nowgrid.x, nowinfo.nowgrid.y, nodetogrid(tonode).x, nodetogrid(tonode).y));*/
  1554. if (stuck) {
  1555. scurstate = 9;
  1556. }
  1557. if (tograduate(api)) {
  1558. scurstate = 2;
  1559. }
  1560. else if (!path.empty()) {
  1561. if ((distant(nowinfo.nowgrid, nodetogrid(path[counter])) >= 2000))
  1562. scurstate = 9;
  1563. else if (distant(nowinfo.nowgrid, nodetogrid(tojuan)) < 100) {
  1564. scurstate = 1;
  1565. }
  1566. }
  1567. else if (distant(nowinfo.nowgrid,nodetogrid(tojuan))<100) {
  1568. scurstate = 1;
  1569. }
  1570. }
  1571. //*************************************************************************************************************************
  1572. // 状态八,开门毕业
  1573. class run :public basicstate {
  1574. public:
  1575. virtual void statemove(IStudentAPI& api);
  1576. virtual void statetransfer(IStudentAPI& api) { ; }
  1577. run(IStudentAPI& api) :basicstate(api) { ; }
  1578. virtual ~run() { ; }
  1579. };
  1580. void run::statemove(IStudentAPI& api) {
  1581. mapnode temp;
  1582. for (int i = 0; i < 8; i++) {
  1583. if (api.GetPlaceType(nowinfo.nownode.x + d8x[i], nowinfo.nownode.y + d8y[i]) == THUAI6::PlaceType::Gate)
  1584. {
  1585. temp = { nowinfo.nownode.x + d8x[i], nowinfo.nownode.y + d8y[i] };
  1586. break;
  1587. }
  1588. }
  1589. if (api.GetSelfInfo()->playerState != THUAI6::PlayerState::OpeningAGate)
  1590. api.StartOpenGate().get();
  1591. api.Graduate();
  1592. }
  1593. //*************************************************************************************************************************
  1594. //状态10,救人
  1595. class save:public basicstate {
  1596. public:
  1597. virtual void statemove(IStudentAPI& api);
  1598. virtual void statetransfer(IStudentAPI& api);
  1599. save(IStudentAPI& api) :basicstate(api) {
  1600. auto id = api.GetSelfInfo()->playerID;
  1601. for (int k = 0; k < 4; k++) {
  1602. if ((id - api.GetStudents()[k]->playerID) == 1)
  1603. tosave = api.GetStudents()[k];
  1604. else if (api.GetStudents()[k]->studentType == THUAI6::StudentType::Teacher)
  1605. another = api.GetStudents()[k];
  1606. };
  1607. mapnode tosavenode = gridtonode({ tosave->x, tosave->y });
  1608. mapnode anothernode = gridtonode({ another->x, another->y });
  1609. }
  1610. virtual ~save() { ; }
  1611. std::shared_ptr<const THUAI6::Student> tosave;
  1612. std::shared_ptr<const THUAI6::Student> another;
  1613. mapnode tosavenode;
  1614. mapnode anothernode;
  1615. void upmap();
  1616. bool inge(IStudentAPI& api);
  1617. };
  1618. bool save::inge(IStudentAPI& api) {
  1619. for (int i = 0; i < 4; i++) {
  1620. if (nowinfo.nownode.x == tosavenode.x + dx[i] && nowinfo.nownode.y == tosavenode.y + dy[i])
  1621. return 1;
  1622. }
  1623. return 0;
  1624. }
  1625. void save::upmap() {
  1626. int xstep = (tosavenode.x - anothernode.x) / abs(tosavenode.x - anothernode.x);
  1627. int ystep = (tosavenode.y - anothernode.y) / abs(tosavenode.y - anothernode.y);
  1628. for (int s = 0; s != (tosavenode.x - anothernode.x) + xstep; s += xstep) {
  1629. wallmap[tosavenode.x + s][tosavenode.y] = 0;
  1630. wallmap[tosavenode.x + s][anothernode.y] = 0;
  1631. }
  1632. for (int s = 0; s != (tosavenode.y - anothernode.y) + ystep; s += ystep) {
  1633. wallmap[tosavenode.x][tosavenode.y + s] = 0;
  1634. wallmap[anothernode.x][tosavenode.y + s] = 0;
  1635. }
  1636. }
  1637. void save::statemove(IStudentAPI& api) {
  1638. insave = 1;
  1639. initialmap(api);
  1640. upmap();
  1641. tonode=poscal(api,tosavenode);
  1642. if (unlockAstar) {
  1643. /*walkcomp(api, nodetogrid(nowinfo.nownode));*/
  1644. pathmerging(nowinfo.nownode, tonode, path, api);
  1645. //api.Print(fmt::format("{},{},{},{},{}", nowinfo.nownode.x, nowinfo.nownode.y, tonode.x, tonode.y, path.size()));
  1646. //for (int i = 0; i < path.size(); i++)
  1647. // api.Print(fmt::format("{},{}\n", path[i].x, path[i].y));
  1648. unlockAstar = 0;
  1649. }
  1650. if (!inge(api)) {
  1651. if (!path.empty()) {
  1652. if (!isarrivend(api)) {
  1653. if (isarrive(api)) {
  1654. /*walkcomp(api, nodetogrid(path[counter - 1]));*/
  1655. ;
  1656. }
  1657. {
  1658. if (!isskipwindow()) {
  1659. walkpath(api);
  1660. }
  1661. else {
  1662. skipwindow(api);
  1663. }
  1664. }
  1665. }
  1666. else {
  1667. walkcomp(api, nodetogrid(tonode));
  1668. unlockAstar = 1;
  1669. }
  1670. }
  1671. }
  1672. else {
  1673. api.StartRouseMate(tosave->playerID);
  1674. }
  1675. }
  1676. void save::statetransfer(IStudentAPI& api) {
  1677. if (tosave->playerState != THUAI6::PlayerState::Addicted) {
  1678. unlockAstar = 1;
  1679. insave = 0;
  1680. scurstate = 2;
  1681. }
  1682. else if (!inge(api) && stuck) {
  1683. scurstate = 9;
  1684. }
  1685. }
  1686. //*************************************************************************************************************************
  1687. //完全体
  1688. class straight{
  1689. public:
  1690. virtual void statemove(IStudentAPI& api);
  1691. virtual void statetransfer(IStudentAPI& api);
  1692. straight(IStudentAPI& api);
  1693. virtual ~straight();
  1694. basicstate* nowstate;
  1695. };
  1696. straight::~straight() {
  1697. delete(nowstate);
  1698. }
  1699. straight::straight(IStudentAPI& api) {
  1700. switch (scurstate) {
  1701. case 3: {nowstate = new gather(api);
  1702. //api.Print("now gather");
  1703. break; }
  1704. case 1: {nowstate = new juan(api);
  1705. //api.Print("now juan");
  1706. break; }
  1707. case 2: {nowstate = new readygraduate(api);
  1708. //api.Print("now readygraduate(");
  1709. break; }
  1710. case 8: {nowstate = new run(api);
  1711. //api.Print("now run");
  1712. break; }
  1713. case 9: {nowstate = new retry(api);
  1714. /* api.Print("now retry"); */
  1715. break; }
  1716. case 10: {nowstate = new save(api);
  1717. //api.Print("now save");
  1718. break; }
  1719. }
  1720. }
  1721. //完全体接口:状态转换
  1722. void straight::statetransfer(IStudentAPI& api) {
  1723. auto a = scurstate;
  1724. nowstate->statetransfer(api);
  1725. if (a == scurstate) {
  1726. ;
  1727. }
  1728. else {
  1729. delete(nowstate);
  1730. switch (scurstate) {
  1731. case 3: {nowstate = new gather(api);
  1732. ///*nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));*/
  1733. //api.Print("now transto gather");
  1734. break; }
  1735. case 1: {nowstate = new juan(api);
  1736. /*nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));*/
  1737. //api.Print("now transto juan");
  1738. break; }
  1739. case 2: {nowstate = new readygraduate(api);
  1740. /*nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));*/
  1741. //api.Print("now transto readygraduate");
  1742. break;}
  1743. case 8: {nowstate = new run(api);
  1744. /*nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));*/
  1745. //api.Print("now transto run");
  1746. break;}
  1747. case 9: {nowstate = new retry(api);
  1748. /*nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));*/
  1749. //api.Print("now transto retry");
  1750. break; }
  1751. case 10: {nowstate = new save(api);
  1752. /*nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));*/
  1753. //api.Print("now transto save");
  1754. break; }
  1755. }
  1756. }
  1757. }
  1758. //完全体接口:状态行动
  1759. void straight::statemove(IStudentAPI& api) {
  1760. nowstate->statemove(api);
  1761. }
  1762. //*************************************************************************************************************************
  1763. //*************************************************************************************************************************
  1764. //*************************************************************************************************************************
  1765. //*************************************************************************************************************************
  1766. //*************************************************************************************************************************
  1767. //*************************************************************************************************************************
  1768. //*************************************************************************************************************************
  1769. int first;
  1770. static bool timego = 0;
  1771. static mapnode pregrid;
  1772. static double prevoice;
  1773. static bool inCD=0;
  1774. struct info2 {
  1775. mapnode nownode;
  1776. mapnode nowgrid;
  1777. double CD[3];
  1778. double dangeralert;
  1779. std::vector<std::shared_ptr<const THUAI6::Student>> Studentinfo;
  1780. };
  1781. //基本状态,封装了走路函数
  1782. class basicstate2 {
  1783. public:
  1784. virtual void statemove(ITrickerAPI& api);
  1785. virtual void statetransfer(ITrickerAPI& api) { ; }
  1786. info2 nowinfo;
  1787. basicstate2(ITrickerAPI& api);
  1788. virtual ~basicstate2();
  1789. void walkpath(ITrickerAPI& api);
  1790. int isarrive(ITrickerAPI& api);
  1791. bool isskipwindow();
  1792. void skipwindow(ITrickerAPI& api);
  1793. bool isarrivend(ITrickerAPI& api);
  1794. bool walkcomp(ITrickerAPI& api, mapnode grid);
  1795. void wallmapupdate(ITrickerAPI& api);
  1796. //void wallmaprefresh(ITrickerAPI& api);
  1797. mapnode tonode;
  1798. bool stuck;
  1799. };
  1800. basicstate2::~basicstate2() {
  1801. lastpos=tonode;
  1802. prevoice = nowinfo.dangeralert;
  1803. pregrid = nowinfo.nowgrid;
  1804. }
  1805. basicstate2::basicstate2(ITrickerAPI& api) {
  1806. if (timego) {
  1807. first = api.GetFrameCount();
  1808. timego = 0;
  1809. }
  1810. if (inCD) {
  1811. auto b = api.GetFrameCount();
  1812. int s = b-first;
  1813. if (s > 800)
  1814. inCD = 0;
  1815. }
  1816. auto self = api.GetSelfInfo();
  1817. nowinfo.nownode.x = api.GridToCell(self->x);
  1818. nowinfo.nownode.y = api.GridToCell(self->y);
  1819. nowinfo.nowgrid.x = self->x;
  1820. nowinfo.nowgrid.y = self->y;
  1821. for (int i = 0; i < 3; i++) {
  1822. nowinfo.CD[i] = self->timeUntilSkillAvailable[i];
  1823. }
  1824. nowinfo.dangeralert = self->trickDesire;
  1825. nowinfo.Studentinfo = api.GetStudents();
  1826. if (!nowinfo.Studentinfo.empty()) {
  1827. for (int i = 0; i < nowinfo.Studentinfo.size(); i++) {
  1828. if (nowinfo.Studentinfo[i]->playerState == THUAI6::PlayerState::Addicted) {
  1829. auto x = api.GridToCell(nowinfo.Studentinfo[i]->x);
  1830. auto y = api.GridToCell(nowinfo.Studentinfo[i]->y);
  1831. wallmap[x][y] = 0;
  1832. }
  1833. }
  1834. }
  1835. if (distant(nowinfo.nowgrid, lastgrid) < 0.1)
  1836. stuck = 1;
  1837. else
  1838. stuck = 0;
  1839. lastgrid.x = self->x;
  1840. lastgrid.y = self->y;
  1841. }
  1842. void basicstate2::statemove(ITrickerAPI& api) {
  1843. api.PrintSelfInfo();
  1844. tonode = { 6,5 };
  1845. if (unlockAstar == 1) {
  1846. pathmerging(nowinfo.nownode, tonode, path, api);
  1847. //api.Print(fmt::format("{}\n", path.size()));
  1848. //for (int i = 0; i < path.size(); i++)
  1849. // api.Print(fmt::format("{},{}\n", path[i].x, path[i].y));
  1850. unlockAstar = 0;
  1851. }
  1852. if (!isarrivend(api)) {
  1853. if (isarrive(api)) {
  1854. walkcomp(api, nodetogrid(path[counter - 1]));
  1855. }
  1856. //else if (flag == 2) {
  1857. // ;
  1858. {
  1859. if (!isskipwindow()) {
  1860. walkpath(api);
  1861. }
  1862. else {
  1863. skipwindow(api);
  1864. }
  1865. }
  1866. }
  1867. }
  1868. int basicstate2::isarrive(ITrickerAPI& api) {
  1869. if (path.empty()||(counter==path.size()-1))
  1870. return 2;
  1871. else if (distant(nowinfo.nowgrid, nodetogrid(path[counter])) <= 100) {
  1872. /*double angle = atan2((path[counter].y - nowinfo.nowgrid.y), (path[counter].x - nowinfo.nowgrid.x));
  1873. int time = distant(nowinfo.nowgrid, nodetogrid(path[counter])) * 1000 / Constants::Sunshine::moveSpeed;
  1874. api.Move(time,angle).get();*/
  1875. //api.Print("arrivedpoint");
  1876. Move(path[counter], path[counter + 1]);
  1877. counter++;
  1878. //api.Print(fmt::format("{}", counter));
  1879. return 1;
  1880. }
  1881. //else if (distant(nowinfo.nowgrid, nodetogrid(path[counter])) >= 2000) {
  1882. // /*api.Print("pianli called");
  1883. // unlockAstar = 1;
  1884. // unlockpos = 1;
  1885. // return 2;*/
  1886. //}
  1887. else return 0;
  1888. }
  1889. bool basicstate2::isarrivend(ITrickerAPI& api) {
  1890. if (distant(nowinfo.nowgrid, nodetogrid(tonode)) < 100)
  1891. return 1;
  1892. else
  1893. return 0;
  1894. }
  1895. void basicstate2::walkpath(ITrickerAPI& api) {
  1896. if (direction == 1) {
  1897. /*api.EndAllAction(); */
  1898. api.MoveUp(70);
  1899. std::this_thread::sleep_for(std::chrono::milliseconds(80));
  1900. }
  1901. if (direction == 2) {
  1902. /*api.EndAllAction(); */
  1903. api.Move(98, P2I * 5).get();
  1904. std::this_thread::sleep_for(std::chrono::milliseconds(108));
  1905. }
  1906. if (direction == 3) {
  1907. /*api.EndAllAction(); */
  1908. api.MoveLeft(70);
  1909. std::this_thread::sleep_for(std::chrono::milliseconds(80));
  1910. }
  1911. if (direction == 4) {
  1912. /*api.EndAllAction(); */
  1913. api.Move(98, P2I * 7);
  1914. std::this_thread::sleep_for(std::chrono::milliseconds(108));
  1915. }
  1916. if (direction == 5) {
  1917. /*api.EndAllAction(); */
  1918. api.MoveDown(70);
  1919. std::this_thread::sleep_for(std::chrono::milliseconds(80));
  1920. }
  1921. if (direction == 6) {
  1922. /*api.EndAllAction(); */
  1923. api.Move(98, P2I);
  1924. std::this_thread::sleep_for(std::chrono::milliseconds(108));
  1925. }
  1926. if (direction == 7) {
  1927. /*api.EndAllAction(); */
  1928. api.MoveRight(70);
  1929. std::this_thread::sleep_for(std::chrono::milliseconds(80));
  1930. }
  1931. if (direction == 8) {
  1932. /*api.EndAllAction(); */
  1933. api.Move(98, P2I * 3);
  1934. std::this_thread::sleep_for(std::chrono::milliseconds(108));
  1935. }
  1936. }
  1937. bool basicstate2::isskipwindow()
  1938. {
  1939. if (wallmap[path[counter].x][path[counter].y] == 2)
  1940. return true;
  1941. else
  1942. return 0;
  1943. }
  1944. void basicstate2::skipwindow(ITrickerAPI& api) {
  1945. if (api.SkipWindow().get()) {
  1946. counter++;
  1947. }
  1948. }
  1949. bool basicstate2::walkcomp(ITrickerAPI& api, mapnode grid) {
  1950. //api.Print("walkcomp called");
  1951. double angle = atan2((grid.y - nowinfo.nowgrid.y), (grid.x - nowinfo.nowgrid.x));
  1952. int time = distant(grid, nowinfo.nowgrid) / 3;
  1953. api.EndAllAction();
  1954. api.Move(time, angle);
  1955. if (time > 100) {
  1956. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  1957. api.EndAllAction();
  1958. }
  1959. else
  1960. std::this_thread::sleep_for(std::chrono::milliseconds(time));
  1961. return 1;
  1962. }
  1963. static mapnode ooo = { -1,-1 };
  1964. void basicstate2::wallmapupdate(ITrickerAPI& api) {
  1965. if (!nowinfo.Studentinfo.empty()) {
  1966. for (int i = 0; i < nowinfo.Studentinfo.size(); i++) {
  1967. int x = nowinfo.Studentinfo[i]->x / 1000, y = nowinfo.Studentinfo[i]->y / 1000;
  1968. //api.Print(fmt::format("{},{},update", x, y));
  1969. if (nowinfo.Studentinfo[i]->playerState == THUAI6::PlayerState::Addicted && ooo.x != x && ooo.y != y) {
  1970. wallmap[x][y] = 0;
  1971. ooo = { x,y };
  1972. //api.Print(fmt::format("{},{},update", x, y));
  1973. unlockAstar = 1;
  1974. }
  1975. if (nowinfo.Studentinfo[i]->playerState == THUAI6::PlayerState::Quit) {
  1976. wallmap[x][y] = 1;
  1977. }
  1978. }
  1979. }
  1980. }
  1981. //****************************************************************************************************
  1982. static int routecount = 0;
  1983. static bool unlockroutecount = 1;
  1984. //全挂了返回假
  1985. bool checkaddict(std::vector<std::shared_ptr<const THUAI6::Student>> student) {
  1986. bool flag = 0;
  1987. for (int i = 0; i < student.size(); i++) {
  1988. if (student[i]->playerState == THUAI6::PlayerState::Addicted) {
  1989. flag = flag;
  1990. }
  1991. else {
  1992. flag = 1;
  1993. }
  1994. }
  1995. return flag;
  1996. }
  1997. //状态1 巡逻
  1998. class route :public basicstate2 {
  1999. public:
  2000. virtual void statemove(ITrickerAPI& api);
  2001. virtual void statetransfer(ITrickerAPI& api);
  2002. route(ITrickerAPI& api) :basicstate2(api) { ; }
  2003. virtual ~route() { ; }
  2004. void handletonode();
  2005. };
  2006. void route::handletonode() {
  2007. if (mapflag == 0) {
  2008. int d = 2147483647, k = 0;
  2009. for (int i = 0; i < routemap.size(); i++) {
  2010. if (distant(nowinfo.nowgrid, routemap[i]) < d) {
  2011. d = distant(nowinfo.nowgrid, routemap[i]);
  2012. k = i;
  2013. }
  2014. }
  2015. routecount = k;
  2016. tonode = routemap[routecount];
  2017. }
  2018. else {
  2019. int d = 2147483647, k = 0;
  2020. for (int i = 0; i < routemap.size(); i++) {
  2021. if (distant(nowinfo.nowgrid, routemap2[i]) < d) {
  2022. d = distant(nowinfo.nowgrid, routemap2[i]);
  2023. k = i;
  2024. }
  2025. }
  2026. routecount = k;
  2027. tonode = routemap2[routecount];
  2028. }
  2029. }
  2030. void route::statemove(ITrickerAPI& api) {
  2031. if (unlockroutecount) {
  2032. handletonode();
  2033. unlockroutecount = 0;
  2034. }
  2035. else {
  2036. if(mapflag==0)
  2037. tonode = routemap[routecount];
  2038. else
  2039. tonode = routemap2[routecount];
  2040. }
  2041. if (unlockAstar == 1) {
  2042. pathmerging(nowinfo.nownode, tonode, path, api);
  2043. //api.Print(fmt::format("{}\n", path.size()));
  2044. //for (int i = 0; i < path.size(); i++)
  2045. // api.Print(fmt::format("{},{}\n", path[i].x, path[i].y));
  2046. unlockAstar = 0;
  2047. }
  2048. if (path.empty()) {
  2049. unlockAstar = 1;
  2050. routecount++;
  2051. if (mapflag == 0)
  2052. routecount %= routemap.size();
  2053. else
  2054. routecount %= routemap2.size();
  2055. }
  2056. if (!path.empty()) {
  2057. if (!isarrivend(api)) {
  2058. if (isarrive(api)==1) {
  2059. walkcomp(api, nodetogrid(path[counter - 1]));
  2060. }
  2061. {
  2062. if (!isskipwindow()) {
  2063. walkpath(api);
  2064. }
  2065. else {
  2066. skipwindow(api);
  2067. }
  2068. }
  2069. }
  2070. else {
  2071. walkcomp(api, nodetogrid(tonode));
  2072. routecount++;
  2073. if(mapflag==0)
  2074. routecount %= routemap.size();
  2075. else
  2076. routecount %= routemap2.size();
  2077. unlockAstar = 1;
  2078. }
  2079. }
  2080. }
  2081. void route::statetransfer(ITrickerAPI& api) {
  2082. if (stuck) {
  2083. unlockAstar = 1;
  2084. tcurstate = 6;
  2085. }
  2086. else if (!nowinfo.Studentinfo.empty() && checkaddict(nowinfo.Studentinfo)) {
  2087. unlockAstar = 1;
  2088. unlockroutecount = 1;
  2089. tcurstate = 3;
  2090. }
  2091. else if (nowinfo.dangeralert >1.7) {
  2092. if (!inCD) {
  2093. unlockAstar = 1;
  2094. unlockroutecount = 1;
  2095. tcurstate = 2;
  2096. timego = 1;
  2097. inCD = 1;
  2098. }
  2099. }
  2100. else if (!path.empty()) {
  2101. if (distant(nowinfo.nowgrid, nodetogrid(path[counter])) > 2000) {
  2102. unlockAstar = 1;
  2103. tcurstate = 6;
  2104. }
  2105. }
  2106. }
  2107. //****************************************************************************************************
  2108. //状态2 运动获取搜索信息
  2109. static mapnode assumepos = {-1,-1};
  2110. class search :public basicstate2 {
  2111. public:
  2112. search(ITrickerAPI& api):basicstate2(api) { ; }
  2113. virtual ~search() { ; }
  2114. virtual void statetransfer(ITrickerAPI& api);
  2115. virtual void statemove(ITrickerAPI& api);
  2116. mapnode soundtrace(ITrickerAPI& api);
  2117. };
  2118. mapnode search::soundtrace(ITrickerAPI& api) {
  2119. api.Wait();
  2120. mapnode now = { api.GetSelfInfo()->x, api.GetSelfInfo()->y };
  2121. double r1 = Constants::Klee::alertnessRadius / api.GetSelfInfo()->trickDesire;
  2122. auto d=api.MoveDown(200).get();
  2123. api.Wait();
  2124. std::this_thread::sleep_for(std::chrono::milliseconds(200));
  2125. api.Wait();
  2126. mapnode now1 = { api.GetSelfInfo()->x, api.GetSelfInfo()->y };
  2127. double d1 = distant(now, now1);
  2128. double r2 = Constants::Klee::alertnessRadius / api.GetSelfInfo()->trickDesire;
  2129. double cosa = (d1 * d1 + r2 * r2 - r1 * r1) / (2.0 * d1 * r2);
  2130. double sina = sqrt(1 - cosa * cosa);
  2131. mapnode assume = { now1.x - (int)r2 * cosa,now1.y + (int)r2 * sina };
  2132. auto a=api.MoveRight(200).get();
  2133. api.Wait();
  2134. std::this_thread::sleep_for(std::chrono::milliseconds(200));
  2135. api.Wait();
  2136. mapnode now2 = { api.GetSelfInfo()->x, api.GetSelfInfo()->y };
  2137. double r3 = Constants::Klee::alertnessRadius / api.GetSelfInfo()->trickDesire;
  2138. double tryd = distant(assume, now2);
  2139. mapnode result;
  2140. if (abs(tryd - r3) < 1000)
  2141. result = gridtonode(assume);
  2142. else {
  2143. assume.y = now1.y - (int)r2 * sina;
  2144. result = gridtonode(assume);
  2145. }
  2146. auto b=api.MoveLeft(200).get();
  2147. api.Wait();
  2148. std::this_thread::sleep_for(std::chrono::milliseconds(200));
  2149. api.Wait();
  2150. auto c=api.MoveUp(200).get();
  2151. api.Wait();
  2152. std::this_thread::sleep_for(std::chrono::milliseconds(200));
  2153. api.Wait();
  2154. return result;
  2155. }
  2156. void search::statemove(ITrickerAPI& api) {
  2157. assumepos = soundtrace(api);
  2158. //api.Print(fmt::format("{},{}", assumepos.x, assumepos.y));
  2159. //std::this_thread::sleep_for(std::chrono::seconds(200));
  2160. }
  2161. void search::statetransfer(ITrickerAPI& api) {
  2162. //if (nowinfo.dangeralert >= 8.5) {
  2163. // unlockAstar = 1;
  2164. // tcurstate = 4;
  2165. //}
  2166. {
  2167. unlockAstar = 1;
  2168. tcurstate = 7;
  2169. }
  2170. }
  2171. //*************************************************************************************************************************
  2172. static bool insearch = 0;
  2173. //状态7 得信息搜索
  2174. class searchinfo :public basicstate2 {
  2175. public:
  2176. searchinfo(ITrickerAPI& api) :basicstate2(api) { ; }
  2177. virtual ~searchinfo() { ; }
  2178. virtual void statetransfer(ITrickerAPI& api);
  2179. virtual void statemove(ITrickerAPI& api);
  2180. int checkalid();
  2181. };
  2182. int searchinfo::checkalid() {
  2183. if (assumepos.x > 49 || assumepos.x < 0 || assumepos.y>49 || assumepos.y < 0)
  2184. return 2;
  2185. else if (wallmap[assumepos.x][assumepos.y])
  2186. return 1;
  2187. else
  2188. return 0;
  2189. }
  2190. void searchinfo::statemove(ITrickerAPI& api) {
  2191. insearch = 1;
  2192. if (checkalid() == 0) {
  2193. tonode = assumepos;
  2194. }
  2195. else if (checkalid() == 1) {
  2196. tonode = poscal(api,assumepos);
  2197. }
  2198. if (unlockAstar == 1) {
  2199. pathmerging(nowinfo.nownode, tonode, path, api);
  2200. unlockAstar = 0;
  2201. }
  2202. if (!path.empty()) {
  2203. if (!isarrivend(api)) {
  2204. if (isarrive(api) == 1) {
  2205. walkcomp(api, nodetogrid(path[counter - 1]));
  2206. }
  2207. {
  2208. if (!isskipwindow()) {
  2209. walkpath(api);
  2210. }
  2211. else {
  2212. skipwindow(api);
  2213. }
  2214. }
  2215. }
  2216. else {
  2217. walkcomp(api, nodetogrid(tonode));
  2218. unlockAstar = 1;
  2219. }
  2220. }
  2221. }
  2222. void searchinfo::statetransfer(ITrickerAPI& api) {
  2223. if (!nowinfo.Studentinfo.empty()) {
  2224. if (checkaddict(nowinfo.Studentinfo)) {
  2225. unlockAstar = 1;
  2226. insearch = 0;
  2227. tcurstate = 3;
  2228. }
  2229. else {
  2230. unlockAstar = 1;
  2231. insearch = 0;
  2232. tcurstate = 1;
  2233. }
  2234. }
  2235. //else if (nowinfo.dangeralert > 8.5&& checkaddict(nowinfo.Studentinfo)) {
  2236. // insearch = 0;
  2237. // tcurstate = 4;
  2238. //}
  2239. else if (distant(nowinfo.nowgrid, nodetogrid(tonode)) < 200||checkalid()==2) {
  2240. unlockroutecount = 1;
  2241. unlockAstar = 1;
  2242. insearch = 0;
  2243. tcurstate = 1;
  2244. }
  2245. else if (stuck) {
  2246. unlockAstar = 1;
  2247. tcurstate = 6;
  2248. }
  2249. else if (!path.empty()) {
  2250. if (distant(nowinfo.nowgrid, nodetogrid(path[counter])) > 2000) {
  2251. unlockAstar = 1;
  2252. tcurstate = 6;
  2253. }
  2254. }
  2255. }
  2256. //*************************************************************************************************************************
  2257. //状态3 有视野追杀
  2258. class kill :public basicstate2 {
  2259. public:
  2260. kill(ITrickerAPI& api) :basicstate2(api) {/* api.Print(fmt::format("aaa"));*/; }
  2261. virtual ~kill() { ; }
  2262. virtual void statemove(ITrickerAPI& api);
  2263. virtual void statetransfer(ITrickerAPI& api);
  2264. int valuecount();
  2265. void skilluse(ITrickerAPI& api);
  2266. //void wallmapupdate();
  2267. //void wallmaprefresh();
  2268. bool inrange();
  2269. void attack(ITrickerAPI& api);
  2270. int p;
  2271. };
  2272. void kill::statetransfer(ITrickerAPI& api) {
  2273. //if (nowinfo.Studentinfo.empty()) {
  2274. // walkcomp(api, nodetogrid(nowinfo.nownode));
  2275. // tcurstate = 2;
  2276. //}
  2277. p = valuecount();
  2278. if (!checkaddict(nowinfo.Studentinfo)) {
  2279. //walkcomp(api, nodetogrid(nowinfo.nownode));
  2280. tcurstate = 1;
  2281. }
  2282. else if (!inrange() && stuck) {
  2283. tcurstate = 6;
  2284. }
  2285. else if (!path.empty()) {
  2286. if (distant(nowinfo.nowgrid, nodetogrid(path[counter])) > 2000) {
  2287. unlockAstar = 1;
  2288. tcurstate = 6;
  2289. }
  2290. }
  2291. }
  2292. void kill::skilluse(ITrickerAPI& api) {
  2293. if (distant(nowinfo.nowgrid, { nowinfo.Studentinfo[p]->x,nowinfo.Studentinfo[p]->y }) < 2000 && nowinfo.CD[0] < 0.1)
  2294. api.UseSkill(0).get();
  2295. }
  2296. bool kill::inrange() {
  2297. if (nowinfo.Studentinfo.size() > 0)
  2298. if (nowinfo.CD[0] < 1) {
  2299. if (distant(nowinfo.nowgrid, { nowinfo.Studentinfo[p]->x,nowinfo.Studentinfo[p]->y }) < 1100)
  2300. return 1;
  2301. else
  2302. return 0;
  2303. }
  2304. else {
  2305. if (distant(nowinfo.nowgrid, { nowinfo.Studentinfo[p]->x,nowinfo.Studentinfo[p]->y }) < 1100)
  2306. return 1;
  2307. else
  2308. return 0;
  2309. }
  2310. else
  2311. return 0;
  2312. }
  2313. void kill::attack(ITrickerAPI& api) {
  2314. double angle;
  2315. angle = atan2(nowinfo.Studentinfo[p]->y - nowinfo.nowgrid.y, nowinfo.Studentinfo[p]->x - nowinfo.nowgrid.x);
  2316. api.Attack(angle).get();
  2317. }
  2318. int kill::valuecount() {
  2319. if (nowinfo.Studentinfo.size() == 1)
  2320. return 0;
  2321. else {
  2322. int d = 1000000000, p = 0;
  2323. for (int i = 0; i < nowinfo.Studentinfo.size(); i++) {
  2324. mapnode temp = { nowinfo.Studentinfo[i]->x,nowinfo.Studentinfo[i]->y };
  2325. if (distant(nowinfo.nowgrid, temp) < d && nowinfo.Studentinfo[i]->playerState != THUAI6::PlayerState::Addicted)
  2326. {
  2327. d = distant(nowinfo.nowgrid, temp);
  2328. p = i;
  2329. }
  2330. }
  2331. return p;
  2332. }
  2333. }
  2334. void kill::statemove(ITrickerAPI& api) {
  2335. p = valuecount();
  2336. //api.Print(fmt::format("1111,{},{},{}", unlockAstar, p, nowinfo.Studentinfo.size()));
  2337. if (nowinfo.Studentinfo.size() > 0) {
  2338. tonode = gridtonode({ nowinfo.Studentinfo[p]->x,nowinfo.Studentinfo[p]->y });
  2339. }
  2340. //api.Print(fmt::format("1111,{},{},{}", unlockAstar, p, nowinfo.Studentinfo.size()));
  2341. if (unlockAstar == 1) {
  2342. pathmerging(nowinfo.nownode, tonode, path, api);
  2343. //api.Print(fmt::format("{}\n", path.size()));
  2344. //for (int i = 0; i < path.size(); i++)
  2345. // api.Print(fmt::format("{},{}\n", path[i].x, path[i].y));
  2346. unlockAstar = 0;
  2347. }
  2348. //api.Print(fmt::format("1111,{},{},{}", unlockAstar, p, nowinfo.Studentinfo.size()));
  2349. if (nowinfo.Studentinfo.size() > 0) {
  2350. skilluse(api);
  2351. }
  2352. if (!inrange()) {
  2353. //api.Print(fmt::format("1111,{},{},{}", unlockAstar, p,counter));
  2354. if (!path.empty()) {
  2355. if (isarrive(api) == 1) {
  2356. /* api.Print(fmt::format("1111,{},{},{}", unlockAstar, p, path.size()));*/
  2357. if (counter >= 1)
  2358. walkcomp(api, nodetogrid(path[counter - 1]));
  2359. }
  2360. {
  2361. if (!isskipwindow()) {
  2362. walkpath(api);
  2363. }
  2364. else {
  2365. skipwindow(api);
  2366. }
  2367. }
  2368. }
  2369. }
  2370. else {
  2371. attack(api);
  2372. unlockAstar = 1;
  2373. }
  2374. }
  2375. //*************************************************************************************************************************
  2376. static int score;
  2377. static bool scoreflag=1;
  2378. //状态4 无视野乱杀
  2379. class randkill :public basicstate2 {
  2380. public:
  2381. randkill(ITrickerAPI& api) :basicstate2(api) { ; }
  2382. virtual ~randkill() { ; }
  2383. virtual void statetransfer(ITrickerAPI& api);
  2384. virtual void statemove(ITrickerAPI& api);
  2385. void skilluse(ITrickerAPI& api);
  2386. void attack(mapnode togrid, ITrickerAPI& api);
  2387. bool givein(ITrickerAPI& api);
  2388. };
  2389. void randkill::skilluse(ITrickerAPI& api) {
  2390. if (nowinfo.CD[0] < 0.1)
  2391. api.UseSkill(0).get();
  2392. }
  2393. void randkill::attack(mapnode togrid, ITrickerAPI& api) {
  2394. double angle = atan2(togrid.y - nowinfo.nowgrid.y, togrid.x - nowinfo.nowgrid.x);
  2395. api.Attack(angle).get();
  2396. }
  2397. void randkill::statemove(ITrickerAPI& api) {
  2398. skilluse(api);
  2399. attack(lastpos,api);
  2400. }
  2401. bool randkill::givein(ITrickerAPI& api) {
  2402. return 1;
  2403. }
  2404. void randkill::statetransfer(ITrickerAPI& api) {
  2405. if (scoreflag) {
  2406. auto a = api.GetGameInfo();
  2407. score = a->trickerScore;
  2408. scoreflag = 0;
  2409. }
  2410. if (givein(api))
  2411. tcurstate = 1;
  2412. }
  2413. //*************************************************************************************************************************
  2414. static bool hoflag=1;
  2415. //状态5 打作业
  2416. class homeworkkill:public kill {
  2417. public:
  2418. homeworkkill(ITrickerAPI& api) :kill(api) { ; }
  2419. virtual ~homeworkkill() { ; }
  2420. virtual void statetransfer(ITrickerAPI& api);
  2421. virtual void statemove(ITrickerAPI& api);
  2422. };
  2423. //*************************************************************************************************************************
  2424. //状态6 鉴定为:重开
  2425. class redo:public basicstate2 {
  2426. public:
  2427. redo(ITrickerAPI& api) :basicstate2(api) { ; }
  2428. virtual ~redo() { ; }
  2429. virtual void statetransfer(ITrickerAPI& api);
  2430. virtual void statemove(ITrickerAPI& api);
  2431. };
  2432. void redo::statemove(ITrickerAPI& api) {
  2433. unlockAstar = 1;
  2434. api.Wait();
  2435. mapnode temp = { api.GetSelfInfo()->x,api.GetSelfInfo()->y };
  2436. mapnode to = nodetogrid(gridtonode(temp));
  2437. double angle = atan2(to.y - temp.y, to.x - temp.x);
  2438. int time;
  2439. time = distant(temp, to) * 1000 / 3600;
  2440. api.EndAllAction();
  2441. api.Move(time, angle).get();
  2442. }
  2443. void redo::statetransfer(ITrickerAPI& api) {
  2444. if (insearch)
  2445. tcurstate = 7;
  2446. else {
  2447. if (!nowinfo.Studentinfo.empty() && checkaddict(nowinfo.Studentinfo))
  2448. tcurstate = 3;
  2449. else {
  2450. tcurstate = 1;
  2451. }
  2452. }
  2453. }
  2454. //*************************************************************************************************************************
  2455. //完全体
  2456. class klee {
  2457. public:
  2458. virtual void statemove(ITrickerAPI& api);
  2459. virtual void statetransfer(ITrickerAPI& api);
  2460. klee(ITrickerAPI& api);
  2461. virtual ~klee();
  2462. basicstate2* nowstate;
  2463. };
  2464. klee::~klee() {
  2465. delete(nowstate);
  2466. }
  2467. klee::klee(ITrickerAPI& api) {
  2468. switch (tcurstate) {
  2469. case 1: {nowstate = new route(api);
  2470. /*api.Print("now gather"); */
  2471. //api.Print("route");
  2472. break; }
  2473. case 3: {
  2474. nowstate = new kill(api);
  2475. //api.Print("kill");
  2476. break;
  2477. }
  2478. case 6: {
  2479. nowstate = new redo(api);
  2480. //api.Print("redo");
  2481. break;
  2482. }
  2483. case 2: {
  2484. nowstate = new search(api);
  2485. //api.Print("search");
  2486. break;
  2487. }
  2488. case 4: {
  2489. nowstate = new randkill(api);
  2490. //api.Print("randkill");
  2491. break;
  2492. }
  2493. case 7: {
  2494. nowstate = new searchinfo(api);
  2495. //api.Print("searchinfo");
  2496. break;
  2497. }
  2498. }
  2499. }
  2500. //完全体接口:状态转换
  2501. void klee::statetransfer(ITrickerAPI& api) {
  2502. auto a = tcurstate;
  2503. nowstate->statetransfer(api);
  2504. if (a == tcurstate) {
  2505. ;
  2506. }
  2507. else {
  2508. delete(nowstate);
  2509. switch (tcurstate) {
  2510. case 1: {
  2511. nowstate = new route(api);
  2512. //nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));
  2513. /*api.Print("now transto gather");*/
  2514. //api.Print("toroute");
  2515. break; }
  2516. case 3: {
  2517. //api.Print(fmt::format("{},aaa", tcurstate));
  2518. nowstate = new kill(api);
  2519. //nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));
  2520. //api.Print(fmt::format("{}", tcurstate));
  2521. //api.Print("tokill");
  2522. break;
  2523. }
  2524. case 6: {
  2525. //api.Print(fmt::format("{},aaa", tcurstate));
  2526. nowstate = new redo(api);
  2527. //nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));
  2528. //api.Print("toredo");
  2529. //api.Print(fmt::format("{}", tcurstate));
  2530. break;
  2531. }
  2532. case 4: {
  2533. //api.Print(fmt::format("{},aaa", tcurstate));
  2534. nowstate = new randkill(api);
  2535. //nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));
  2536. /* api.Print("torandkill");*/
  2537. //api.Print(fmt::format("{}", tcurstate));
  2538. break;
  2539. }
  2540. case 2: {
  2541. //api.Print(fmt::format("{},aaa", tcurstate));
  2542. nowstate = new search(api);
  2543. ////nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));
  2544. //api.Print("tosearch");
  2545. //api.Print(fmt::format("{}", tcurstate));
  2546. break;
  2547. }
  2548. case 7: {
  2549. //api.Print(fmt::format("{},aaa", tcurstate));
  2550. nowstate = new searchinfo(api);
  2551. ////nowstate->walkcomp(api, nodetogrid(nowstate->nowinfo.nownode));
  2552. //api.Print("tosearchinfo");
  2553. //api.Print(fmt::format("{}", tcurstate));
  2554. break;
  2555. }
  2556. }
  2557. }
  2558. }
  2559. //完全体接口:状态行动
  2560. void klee::statemove(ITrickerAPI& api) {
  2561. nowstate->statemove(api);
  2562. }
  2563. //static bool flagaa = 1;
  2564. void AI::play(IStudentAPI& api)
  2565. {
  2566. if (this->playerID == 0)
  2567. {
  2568. /*api.PrintSelfInfo();*/
  2569. initialmap(api);
  2570. teacherall a(api);
  2571. a.statetransfer(api);
  2572. a.statemove(api);
  2573. //initialmap(api);
  2574. //straight a(api);
  2575. //a.statetransfer(api);
  2576. //a.statemove(api);
  2577. }
  2578. else if (this->playerID == 1)
  2579. {
  2580. /*api.PrintSelfInfo();*/
  2581. initialmap(api);
  2582. straight a(api);
  2583. a.statetransfer(api);
  2584. a.statemove(api);
  2585. }
  2586. else if (this->playerID == 2)
  2587. {
  2588. /*api.PrintSelfInfo();*/
  2589. initialmap(api);
  2590. teacherall a(api);
  2591. a.statetransfer(api);
  2592. a.statemove(api);
  2593. //initialmap(api);
  2594. //straight a(api);
  2595. //a.statetransfer(api);
  2596. //a.statemove(api);
  2597. }
  2598. else if (this->playerID == 3)
  2599. {
  2600. /*api.PrintSelfInfo();*/
  2601. initialmap(api);
  2602. straight a(api);
  2603. a.statetransfer(api);
  2604. a.statemove(api);
  2605. }
  2606. // 当然可以写成if (this->playerID == 2||this->playerID == 3)之类的操作
  2607. // 公共操作
  2608. }
  2609. void AI::play(ITrickerAPI& api)
  2610. {
  2611. initialmap(api);
  2612. klee a(api);
  2613. a.statetransfer(api);
  2614. a.statemove(api);
  2615. }