Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Attack Order Shuffle

Author
Message
Cafe Casita
15
Years of Service
User Offline
Joined: 1st Jun 2011
Location: Eureka, FLA
Posted: 29th Oct 2012 06:38
Hi,
I need to "get" some code for shuffling an Order of Attack for up to 37 on board characters.
I found a snippet called "Swap Array Items" at:
http://www.matrix1.demon.co.uk/Matrix1Utils_Help/Matrix1Util_29/swap_array_items.html

It doesn't work, but then I'm like 6 months doing programming. The word, I believe is "Sophomore".

Here's my code:

REMSTART - My dillemma. Shuffle the order of attack of up to
37 Souls On Board. I found this piece of code at
http://www.matrix1.demon.co.uk/Matrix1Utils_Help/Matrix1Util_29/swap_array_items.html
Remarks highlighted by "***" show my distress.
REMEND




REM - This file is shuffleatkord.dba

REM - Get all sob's (Souls On Board)
REM - TC's are Characters controlled by players
REM - EC's are Enemy Characters controlled by AI
REM - AC's are Army Characters controlled by AI

DATA "TC1","TC2","TC3","TC4","TC5","TC6","EC11","EC12","EC13","EC14"
DATA "EC15","EC16","EC17","EC18","EC19","EC20","EC21","EC22","AC31"
DATA "AC32","AC33","AC34","AC35","AC36","AC37","AC38","AC39"
DATA "AC40","AC41","AC42","AC43","AC44","AC45","AC46","AC47"
DATA "AC48","AC49","AC50"

DIM Array(37)

FOR I=0 to 36

READ Array(I)

NEXT I

FOR CHG=1 TO 11

DOOVER:

randomize timer()

IT1#=RND(37)
IT2#=RND(37)

REM - print is for testing the goto do()over IF

print IT1#;" ";IT2#

suspend for key

IF IT1#=IT2#
GOTO DOOVER
ENDIF

REM - *** The "Miracle" should happen here!!!

REM - *** How is this code "supposed" to be written?

SWAP ARRAY ITEMS Array(), Index 1, Index2

REM - *** I "Imagine" it should look like this:

SWAP ARRAY ITEMS Array(), IT1#, IT2#

REM - *** Of course "My theory" doesn't work!!!

NEXT CHG

RESTORE

FOR ATKORD=1 TO 11

READ Array(ATKORD)

NEXT CHG

PRINT Array(1);" ";Array(2);" ";Array(3)
PRINT Array(4);" ";Array(5);" ";Array(6)
PRINT Array(7);" ";Array(8);" ";Array(9)
PRINT Array(10);" ";Array(11)

SUSPEND FOR KEY

Thank you all, greatly,

Cafe Casita

Cafe Casita says YES
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Oct 2012 10:53
So you just want to swap items in an array randomly? Something like this should work:



The more you loop through it, the more random it gets. I suggest using a number over the array size (37), but using something too high doesn't really give you more randomness and just wastes time.

TheComet

- The codebase
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Oct 2012 23:09
Is there a reason you made two posts about this?

http://forum.thegamecreators.com/?m=forum_view&t=201124&b=1

"You're not going crazy. You're going sane in a crazy world!" ~Tick

Login to post a reply

Server time is: 2026-07-11 00:07:01
Your offset time is: 2026-07-11 00:07:01