pvpoke / pvpoke

Open-Source Battle Simulator, Rankings & Team Building for Pokemon GO PvP
MIT License
308 stars 152 forks source link

Proposal: node module #50

Open nrkn opened 4 years ago

nrkn commented 4 years ago

Would you be interested in working together to extract the core logic into a node module?

I've done a simple proof of concept/prototype that just does some of the stuff that was easy to port over:

https://github.com/nrkn/pvpoke-node

I started it because I wanted to use bits and pieces of the code from the command line to help me with my own team building etc, just ad hoc little things that wouldn't be worth adding to pvpoke in general, but I couldn't run it outside the browser as is

If you're interested, I'd be happy to move the repo over to this organization and just work as a contributor

Be forewarned, it's quite different in style to your code, the readme has justifications/excuses for why that is - I'm happy to discuss adapting it to something that would suit you better if need be

My email is in my profile if you'd rather discuss this that way

nrkn commented 4 years ago

I've also temporarily hacked together a straight port to ts/node here, I'm going to try to run a battle when I get back from lunch:

https://github.com/nrkn/pvpoke/tree/node-module

nrkn commented 4 years ago

Blew the heap out, but promising nonetheless!

import { RankerMaster } from '../lib/battle/RankerIdenticalTest'

const ranker = RankerMaster.getInstance()

const result = ranker.rank( 1500, [ 2, 2 ] )

console.log( result )
C:\Users\Nik Coughlin\Documents\GitHub\pvpoke>tsc && node ./dist/sandbox
basculin vs. archeops 768 archeops vs. basculin 796
beartic vs. ariados 489 ariados vs. beartic 527
beedrill vs. abomasnow 757 abomasnow vs. beedrill 773
beedrill vs. ambipom 392 ambipom vs. beedrill 384
braviary vs. bouffalant 437 bouffalant vs. braviary 426
carracosta vs. aron 720 aron vs. carracosta 737
charmeleon vs. arbok 611 arbok vs. charmeleon 654
clamperl vs. chandelure 782 chandelure vs. clamperl 792
cobalion vs. abomasnow 536 abomasnow vs. cobalion 820
corsola vs. corphish 531 corphish vs. corsola 555
croconaw vs. chandelure 837 chandelure vs. croconaw 844
darkrai vs. blastoise 209 blastoise vs. darkrai 229
darkrai vs. croconaw 196 croconaw vs. darkrai 215
deoxys vs. beartic 213 beartic vs. deoxys 217
deoxys_speed vs. bellossom 82 bellossom vs. deoxys_speed 89
dewott vs. dewgong 408 dewgong vs. dewott 496
drapion vs. darmanitan_zen 706 darmanitan_zen vs. drapion 732
druddigon vs. castform 500 castform vs. druddigon 517
dugtrio vs. crustle 393 crustle vs. dugtrio 200
electrode vs. castform 434 castform vs. electrode 448
elekid vs. cobalion 725 cobalion vs. elekid 712
emolga vs. cobalion 777 cobalion vs. emolga 742
exeggutor_alolan vs. dragonair 352 dragonair vs. exeggutor_alolan 410
ferrothorn vs. alakazam 450 alakazam vs. ferrothorn 478
flygon vs. aerodactyl 333 aerodactyl vs. flygon 341
forretress vs. espeon 785 espeon vs. forretress 820
forretress vs. exeggutor_alolan 816 exeggutor_alolan vs. forretress 835
genesect vs. cobalion 671 cobalion vs. genesect 656
genesect_douse vs. cobalion 671 cobalion vs. genesect_douse 656
gigalith vs. castform_rainy 375 castform_rainy vs. gigalith 386
gigalith vs. dewott 441 dewott vs. gigalith 455
giratina_origin vs. aerodactyl 308 aerodactyl vs. giratina_origin 333
giratina_origin vs. carnivine 286 carnivine vs. giratina_origin 310
gliscor vs. gigalith 560 gigalith vs. gliscor 526
golduck vs. gigalith 531 gigalith vs. golduck 542
golem vs. bibarel 107 bibarel vs. golem 120
golem vs. golduck 96 golduck vs. golem 108
golurk vs. druddigon 342 druddigon vs. golurk 390
granbull vs. gligar 737 gligar vs. granbull 718
grotle vs. deoxys_speed 760 deoxys_speed vs. grotle 791
growlithe vs. deoxys_speed 826 deoxys_speed vs. growlithe 838
growlithe vs. dusknoir 716 dusknoir vs. growlithe 744
gurdurr vs. drifblim 480 drifblim vs. gurdurr 495
gurdurr vs. garbodor 628 garbodor vs. gurdurr 488
hariyama vs. armaldo 669 armaldo vs. hariyama 838
hariyama vs. garbodor 778 garbodor vs. hariyama 496
hippopotas vs. deoxys_speed 758 deoxys_speed vs. hippopotas 789
hippowdon vs. deoxys_speed 775 deoxys_speed vs. hippowdon 803
hippowdon vs. dusknoir 814 dusknoir vs. hippowdon 832
ho_oh vs. hitmontop 747 hitmontop vs. ho_oh 637
huntail vs. archeops 759 archeops vs. huntail 789
huntail vs. giratina_origin 671 giratina_origin vs. huntail 696
hypno vs. hydreigon 209 hydreigon vs. hypno 486
illumise vs. hitmonchan 278 hitmonchan vs. illumise 298
infernape vs. chatot 274 chatot vs. infernape 319
infernape vs. heatmor 295 heatmor vs. infernape 268
jellicent vs. dusknoir 494 dusknoir vs. jellicent 608
jumpluff vs. amoonguss 272 amoonguss vs. jumpluff 283
kabutops vs. cobalion 633 cobalion vs. kabutops 638
kangaskhan vs. electrode 697 electrode vs. kangaskhan 734
kangaskhan vs. grovyle 307 grovyle vs. kangaskhan 337
kecleon vs. kangaskhan 453 kangaskhan vs. kecleon 288
keldeo_ordinary vs. genesect_burn 166 genesect_burn vs. keldeo_ordinary 161
keldeo_ordinary vs. genesect_chill 166 genesect_chill vs. keldeo_ordinary 161
keldeo_resolute vs. genesect_burn 166 genesect_burn vs. keldeo_resolute 161
keldeo_resolute vs. genesect_chill 166 genesect_chill vs. keldeo_resolute 161
klinklang vs. aggron 757 aggron vs. klinklang 776
krookodile vs. dragonite 192 dragonite vs. krookodile 215
krookodile vs. forretress 132 forretress vs. krookodile 148
kyurem_white vs. gallade 433 gallade vs. kyurem_white 582
lanturn vs. fraxure 258 fraxure vs. lanturn 270
lapras vs. alakazam 817 alakazam vs. lapras 828
lapras vs. aron 817 aron vs. lapras 828
lapras vs. darkrai 812 darkrai vs. lapras 828
loudred vs. garbodor 492 garbodor vs. loudred 480
luxio vs. giratina_origin 652 giratina_origin vs. luxio 679
machamp vs. boldore 754 boldore vs. machamp 717
mandibuzz vs. gigalith 441 gigalith vs. mandibuzz 415
marowak vs. bibarel 366 bibarel vs. marowak 401
marowak vs. croconaw 310 croconaw vs. marowak 340
marowak vs. feraligatr 368 feraligatr vs. marowak 404
marowak_alolan vs. arcanine 278 arcanine vs. marowak_alolan 467
marshtomp vs. marowak 634 marowak vs. marshtomp 666
meganium vs. castform 641 castform vs. meganium 656
melmetal vs. arceus_ice 678 arceus_ice vs. melmetal 660
melmetal vs. crawdaunt 520 crawdaunt vs. melmetal 266
melmetal vs. cresselia 611 cresselia vs. melmetal 601
melmetal vs. lileep 611 lileep vs. melmetal 559
melmetal vs. mandibuzz 604 mandibuzz vs. melmetal 629
meloetta_pirouette vs. castform_snowy 300 castform_snowy vs. meloetta_pirouette 282
metang vs. ledian 437 ledian vs. metang 291
mew vs. grimer_alolan 154 grimer_alolan vs. mew 166
mienfoo vs. kingdra 195 kingdra vs. mienfoo 213
mightyena vs. arceus_psychic 871 arceus_psychic vs. mightyena 882
mightyena vs. celebi 875 celebi vs. mightyena 890
mightyena vs. cryogonal 571 cryogonal vs. mightyena 659
milotic vs. blastoise 391 blastoise vs. milotic 411
milotic vs. croconaw 439 croconaw vs. milotic 462
milotic vs. feraligatr 468 feraligatr vs. milotic 492
miltank vs. chansey 682 chansey vs. miltank 602
miltank vs. deoxys 877 deoxys vs. miltank 884
miltank vs. houndoom 566 houndoom vs. miltank 582
miltank vs. magby 486 magby vs. miltank 500
minun vs. deoxys 579 deoxys vs. minun 863
misdreavus vs. jellicent 417 jellicent vs. misdreavus 461
mismagius vs. drapion 92 drapion vs. mismagius 100
monferno vs. dragonair 352 dragonair vs. monferno 387
munchlax vs. arceus_poison 900 arceus_poison vs. munchlax 896
munchlax vs. camerupt 713 camerupt vs. munchlax 698
munchlax vs. dwebble 533 dwebble vs. munchlax 509
munchlax vs. escavalier 277 escavalier vs. munchlax 268
munchlax vs. ferrothorn 641 ferrothorn vs. munchlax 459
munchlax vs. forretress 583 forretress vs. munchlax 538
nidorina vs. deoxys_speed 874 deoxys_speed vs. nidorina 884
omanyte vs. golem 819 golem vs. omanyte 835
omanyte vs. graveler 819 graveler vs. omanyte 835
omastar vs. abomasnow 262 abomasnow vs. omastar 40
omastar vs. omanyte 298 omanyte vs. omastar 252
pachirisu vs. cinccino 507 cinccino vs. pachirisu 544
parasect vs. cobalion 677 cobalion vs. parasect 578
pawniard vs. cobalion 685 cobalion vs. pawniard 436
pawniard vs. hypno 831 hypno vs. pawniard 849
pawniard vs. krabby 659 krabby vs. pawniard 500
pawniard vs. lickilicky 663 lickilicky vs. pawniard 526
pawniard vs. miltank 659 miltank vs. pawniard 654
persian vs. cobalion 641 cobalion vs. persian 645
persian vs. corphish 690 corphish vs. persian 729
persian vs. deoxys 881 deoxys vs. persian 889
piloswine vs. deoxys 577 deoxys vs. piloswine 590
piloswine vs. omanyte 242 omanyte vs. piloswine 257
pinsir vs. crawdaunt 454 crawdaunt vs. pinsir 467
plusle vs. pinsir 345 pinsir vs. plusle 335
poliwhirl vs. cobalion 850 cobalion vs. poliwhirl 835
poliwhirl vs. emolga 218 emolga vs. poliwhirl 226
prinplup vs. bouffalant 539 bouffalant vs. prinplup 547
prinplup vs. klang 429 klang vs. prinplup 358
probopass vs. houndoom 902 houndoom vs. probopass 906
pupitar vs. castform_sunny 623 castform_sunny vs. pupitar 634
quagsire vs. melmetal 527 melmetal vs. quagsire 533
quilava vs. accelgor 884 accelgor vs. quilava 876
quilava vs. azumarill 158 azumarill vs. quilava 169
qwilfish vs. archeops 764 archeops vs. qwilfish 793
raichu_alolan vs. escavalier 148 escavalier vs. raichu_alolan 162
raichu_alolan vs. melmetal 844 melmetal vs. raichu_alolan 816
raikou vs. hippopotas 251 hippopotas vs. raikou 258
rayquaza vs. altaria 244 altaria vs. rayquaza 284
registeel vs. cradily 679 cradily vs. registeel 764
registeel vs. exeggutor_alolan 752 exeggutor_alolan vs. registeel 692
relicanth vs. basculin 406 basculin vs. relicanth 300
relicanth vs. gigalith 624 gigalith vs. relicanth 634
relicanth vs. huntail 465 huntail vs. relicanth 362
rhydon vs. altaria 127 altaria vs. rhydon 138
rhydon vs. mothim 165 mothim vs. rhydon 179
rhyperior vs. castform_snowy 746 castform_snowy vs. rhyperior 701
rotom vs. armaldo 420 armaldo vs. rotom 221
rotom_fan vs. cradily 485 cradily vs. rotom_fan 634

<--- Last few GCs --->

[22084:000001E51DAA8E20]    34857 ms: Scavenge 1390.1 (1421.3) -> 1389.2 (1421.8) MB, 3.2 / 0.0 ms  (average mu = 0.191, current mu = 0.136) allocation failure
[22084:000001E51DAA8E20]    34863 ms: Scavenge 1390.2 (1421.8) -> 1389.3 (1422.3) MB, 3.1 / 0.0 ms  (average mu = 0.191, current mu = 0.136) allocation failure
[22084:000001E51DAA8E20]    34867 ms: Scavenge 1390.3 (1422.3) -> 1389.4 (1423.3) MB, 2.8 / 0.0 ms  (average mu = 0.191, current mu = 0.136) allocation failure

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0000034D78B5C6C1]
    1: StubFrame [pc: 0000034D78B0D62B]
    2: ConstructFrame [pc: 0000034D78B0D1C3]
Security context: 0x00da4fa9e681 <JSObject>
    3: /* anonymous */ [000002BA0C136179] [C:\Users\Nik Coughlin\Documents\GitHub\pvpoke\dist\lib\battle\Battle.js:~750] [pc=0000034D7916F5B8](this=0x00ae1c5926d9 <Battle map = 0000031A904D3719>,poke=0x00daf92269a9 <Pokemon map = 0000031A904ED761>,opponent=0x0242a6538351 <...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF7E683EEE5
 2: 00007FF7E6818CD6
 3: 00007FF7E68196E0
 4: 00007FF7E6C80D3E
 5: 00007FF7E6C80C6F
 6: 00007FF7E6BCC594
 7: 00007FF7E6BC2B67
 8: 00007FF7E6BC10DC
 9: 00007FF7E6BCA0B7
10: 00007FF7E6BCA136
11: 00007FF7E6CEF7B7
12: 00007FF7E6DC87FA
13: 0000034D78B5C6C1
pvpoke commented 4 years ago

Hey, so sorry it took me so long to respond to this! This is a fantastic project. I don't have any plans to move the actual site over to Node but it would be really cool to have this as a related project. Thoughts on the best way to set that up?

nrkn commented 4 years ago

I think the site is probably fine how it is, using php on the back

Sorry about the incoming novel...

There are a few paths forward for this to exist as a related project - it depends on how involved you want to be


The least work for you, which I've done a feasibility test for that indicated it would be viable, is that the node module has a build script that clones current pvpoke, pulls out just the json and the javascript that does logic, ignoring the interface stuff, and polyfills out a minimal jquery replacement - you use jquery heavily in the interfaces, but in your logic js you barely use it, the only things you use are $.each, $.getJson and, in the ranker stuff, $.ajax to post back to the server - so a pretty small surface to emulate. If you replaced the the handful of places you use $.each with standard Array.prototype.forEach (syntax is near identical) it would be even easier. Then the build script concatenates the js together and exports the appropriate stuff for use from node.

Pros: you don't have to do anything - you're already doing a massive amount of work on pvpoke and I'm sure you don't need more on your plate! Cons: quite a bit of code for me to write to get it working, build has to be updated whenever you update and cloning/pulling apart/putting back together is heavy, slow, fragile if you make architectural changes it might break etc. I could see it being a pain and my not wanting to maintain it after a while, but maybe there would be community interest to help out.


The next easiest, would be, for you to remove what little jquery stuff is in the logic completely and have the constructors/factories etc take any data they need as an argument rather than fetching it themselves via ajax - from your point of view, not much would change except you make your ajax call first and then pass the data into your functions. Then nothing would need to be stubbed out on my end, and it would just be a matter of pulling out the appropriate js and bundling it up and exporting stuff

Pros: you don't have to do much, considerably less work to turn in into a package than above Cons: still a bit of code to write to bundle for node, still have to clone/etc when updating - feels clunky as it's the reverse of how one would normally do it, which is where the next approach comes in...


The next easiest after that, would be a straight port to node, eg take just the logic parts, get rid of jquery in those files, add exports and imports instead of them being in the global namespace like they currently are in the browser, publish as a node module with a bundle for the browser as well using browserify or webpack, then in pvpoke you pull that browser bundle in. From your point of view not much would change except that when you make changes to the logic you'd do it in the project for the node module rather than directly in the pvpoke project and then publish the module and use the browser bundle on the website. Only the logic parts change, you keep all your existing interface code etc

Pros: this is how you'd normally share code between node/the browser, less work for me except for guiding you through the initial setup if you're not familiar with the node ecosystem (and if you are, even less work, lol) - also makes writing unit tests and things like that easy Cons: instead of just working directly in the js like you are now, when you want to make changes you do have to push to a separate project, run the build script to bundle for the browser, publish the module, and add the bundled script to pvpoke - and I can understand how much easier it can be just to work directly on js being run in the browser where all you have to do to see your changes is hit f5!


The most work of all, and the approach I took in the first project linked at top of this thread, is to completely break everything up into small functions, use typescript and create a very modular, reusable code base - basically a pokemon go simulation library - the reason i took this approach is that i've been working on medium to large code bases in js for a while and I ended up working like this to stay on top of the complexity, otherwise I start getting anxious lol

Pros: can use it for all kinds of related things, makes unit testing a breeze because testing small parts at a time, using typescript gives you a great experience in editors like VS Code, also makes profiling for performance easy, makes refactoring easy etc Cons: it's quite a lot of work and you'd have to be happy getting comfortable with typescript etc. - same cons as previous path apply too, in terms of extra steps for deploying a new version

aakropotkin commented 4 years ago

If you have a fork add me to it. I have a lot of typescript experience and am interested in contributing. On a somewhat related note, I've built up a solid chunk of a Clojure library if there is any interest in that.

matyapiro31 commented 4 years ago

@nrkn Is node module latest?

nrkn commented 4 years ago

@nrkn Is node module latest?

@matyapiro31 sorry for the late reply, I've been home sick - this is the latest that I worked on, just polyfills some of jquery so you can run some of pvpoke from node - it isn't up to date with pvpoke master though

https://github.com/nrkn/pvpoke/tree/node-module

nrkn commented 4 years ago

@alexameen apologies also for late response - would you be interested in working together on

a) a straight port of pvpoke to typescript eg https://github.com/nrkn/pvpoke/tree/node-module

or b) a full ts rewrite based on pvpoke eg https://github.com/nrkn/pvpoke-node

aakropotkin commented 4 years ago

@alexameen apologies also for late response - would you be interested in working together on

a) a straight port of pvpoke to typescript eg https://github.com/nrkn/pvpoke/tree/node-module

or b) a full ts rewrite based on pvpoke eg https://github.com/nrkn/pvpoke-node

Hey sorry for the super late reply. The virus thing mixed things up pretty good for a while and I totally forgot about this. I will clone those repos and see what I can do to help.

simonh1000 commented 4 years ago

I'd be interested to help. My interest is to factor out the core ranking and team libraries so that they can be used by separate UIs. In addition, as I'm a functional programmer I'd be keen to help reduce the class complexity which I'm incapable of understanding (my weakness of course)!