For some reason, mafia is destroying the original map.
... which results as:
Original List:
originalList[0]: 1000
originalList[1]: 1001
originalList[2]: 1002
originalList[3]: 1003
originalList[4]: 1004
originalList[5]: 1005
originalList[6]: 1006
#############
Randomized List 1:
randomizedList[0]: 1004
randomizedList[1]: 1005
randomizedList[2]: 1000
randomizedList[3]: 1001
randomizedList[4]: 1002
randomizedList[5]: 1006
randomizedList[6]: 1003
Original List
originalList[0]: 1000 <--- (varies)
originalList[1]: 0
originalList[2]: 0
originalList[3]: 0
originalList[4]: 0
originalList[5]: 0
originalList[6]: 0
############
randomize function:
input[0]: 1000 <--- (varies)
input[1]: 0
input[2]: 0
input[3]: 0
input[4]: 0
input[5]: 0
input[6]: 0
Randomized List 2:
randomizedList[0]: 0
randomizedList[1]: 0
randomizedList[2]: 1000 <--- (varies)
randomizedList[3]: 0
randomizedList[4]: 0
randomizedList[5]: 0
randomizedList[6]: 0
So, the real problem is that 2 successive calls of 'randomize' destroys the original list in the main() function.
randomizedList = randomizeList(originalList,true);
randomizedList = randomizeList(originalList,true);
Can anyone help/explain?
Code:
int[int] randomizeList(int[int] input, boolean readout){
int elementCount = count(input);
int randNum;
int[int] rndList;
if(readout){
print("randomize function:","red");
foreach i in input{
print("input["+i+"]: "+input[i],"red");
}
}
if(elementCount<2){
rndList[0] = input[0];
return rndList;
}
if(elementCount==2){
randNum = random(2);
rndList[0] = input[randNum];
rndList[1] = input[1-randNum];
return rndList;
}
### mafia enforces range min of 2, so need (elementCount-1)-1 = elementCount-2
for i from 0 to (elementCount-2){
randNum = random(elementCount-i);
rndList[i] = input[randNum];
### "remove" input[randNum] from rndList
for j from randNum to (elementCount-i-1){
input[j]=input[j+1];
}
}
rndList[elementCount-1]=input[0];
return rndList;
}
Code:
void main(){
int[int] originalList;
int[int] randomizedList;
originalList[0] = 1000;
originalList[1] = 1001;
originalList[2] = 1002;
originalList[3] = 1003;
originalList[4] = 1004;
originalList[5] = 1005;
originalList[6] = 1006;
cli_execute("cls");
print("Original List:","blue");
foreach i in originalList{
print("originalList["+i+"]: "+originalList[i],"green");
}
print("#############");
randomizedList = randomizeList(originalList,false);
print("Randomized List 1:","blue");
foreach i in randomizedList{
print("randomizedList["+i+"]: "+randomizedList[i],"green");
}
print("Original List","blue");
foreach i in originalList{
print("originalList["+i+"]: "+originalList[i],"green");
}
print("############");
randomizedList = randomizeList(originalList,true);
print("Randomized List 2:","blue");
foreach i in randomizedList{
print("randomizedList["+i+"]: "+randomizedList[i],"green");
}
print(" ");
}
... which results as:
Original List:
originalList[0]: 1000
originalList[1]: 1001
originalList[2]: 1002
originalList[3]: 1003
originalList[4]: 1004
originalList[5]: 1005
originalList[6]: 1006
#############
Randomized List 1:
randomizedList[0]: 1004
randomizedList[1]: 1005
randomizedList[2]: 1000
randomizedList[3]: 1001
randomizedList[4]: 1002
randomizedList[5]: 1006
randomizedList[6]: 1003
Original List
originalList[0]: 1000 <--- (varies)
originalList[1]: 0
originalList[2]: 0
originalList[3]: 0
originalList[4]: 0
originalList[5]: 0
originalList[6]: 0
############
randomize function:
input[0]: 1000 <--- (varies)
input[1]: 0
input[2]: 0
input[3]: 0
input[4]: 0
input[5]: 0
input[6]: 0
Randomized List 2:
randomizedList[0]: 0
randomizedList[1]: 0
randomizedList[2]: 1000 <--- (varies)
randomizedList[3]: 0
randomizedList[4]: 0
randomizedList[5]: 0
randomizedList[6]: 0
So, the real problem is that 2 successive calls of 'randomize' destroys the original list in the main() function.
randomizedList = randomizeList(originalList,true);
randomizedList = randomizeList(originalList,true);
Can anyone help/explain?
Last edited: