瀏覽代碼

Bugfix in mutator when len(expr) == 1

Yann Weber 6 年之前
父節點
當前提交
ec4e4a9951
共有 1 個檔案被更改,包括 4 行新增1 行删除
  1. 4
    1
      gte/mutator.py

+ 4
- 1
gte/mutator.py 查看文件

64
     return expr
64
     return expr
65
 
65
 
66
 def mutupdtype(expr):
66
 def mutupdtype(expr):
67
-    pos = randint(0, len(expr) - 1)
67
+    if len(expr) == 1:
68
+        pos = 0
69
+    else:
70
+        pos = randint(0, len(expr) - 1)
68
     optype = [RpnSymbol.OPERATION, RpnSymbol.VALUE, RpnSymbol.VARIABLE]
71
     optype = [RpnSymbol.OPERATION, RpnSymbol.VALUE, RpnSymbol.VARIABLE]
69
     del(optype[optype.index(expr[pos].optype)])
72
     del(optype[optype.index(expr[pos].optype)])
70
     expr[pos] = RpnSymbol.random(optype[randint(0,1)])
73
     expr[pos] = RpnSymbol.random(optype[randint(0,1)])

Loading…
取消
儲存