打印时如何从矩阵中删除科学计数法
game_data = '1. e3 e5,2. Qh5 Qf6,3. Qf3 Nc6,4. Qxf6 Nxf6,5. Nf3 d6,6. g3 Nb4,7. Bg2 Nxc2+,8. Kd1 Nxa1,9. b4 Bd7,10. Bb2 Ba4+,11. Kc1 Nc2,12. d4 exd4,13. exd4 d5,14. Nfd2 Bxb4,15. Nf3 Ne4,16. Ba3 Nxa3,17. Nxa3 Bxa3+,18. Kb1 Nc3+,19. Ka1 Bc2,20. Rc1 Bxc1,21. Ne5 Na4,22. Bxd5 Bb2#'
game_data_split = game_data.split(',')
#print(game_data_split)
alphabet = 'abcdefgh'
#below is just a chess board
board = [
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
]
for item in game_data_split:
#we are going to have to add something to deal with check as a boolean changing every move, or in the middle of every move if white is put in check
turn,white,black = item.split()
if white == 'O-O-O':
x = [0,1,2]
y = 0
board[x][y] += 0.1
if white.endswith('+'):
x = alphabet.index(white[-3])
y = int(white[-2]) -1
board[y][x] += 0.01
elif white.endswith('#'):
x = alphabet.index(white[-3])
y = int(white[-2]) -1
board[y][x] += 0.001
else:
x = alphabet.index(white[-2])
y = int(white[-1]) - 1
board[y][x] += 0.00001
if black == 'O-O-O':
x = [5,6,7]
y = [7]
board[y][x] += 1
if black.endswith('+'):
x = alphabet.index(black[-3])
y = int(black[-2]) -1
board[y][x] += 10
elif black.endswith('#'):
x = alphabet.index(black[-3])
y = int(black[-2]) -1
board[y][x] += 100
else:
x = alphabet.index(black[-2])
y = int(black[-1]) - 1
board[y][x] +=1000
print(turn)
pprint(board)
我正在构建一个棋盘可视化器来学习,我的结果似乎正确显示,但我不断得到像 1e-05 甚至 3.0000000000000004e-05 这样的结果。我真的不想在我的结果中使用这种科学记数法。如何让印制板停止显示科学计数法?
game_data = '1. e3 e5,2. Qh5 Qf6,3. Qf3 Nc6,4. Qxf6 Nxf6,5. Nf3 d6,6. g3 Nb4,7. Bg2 Nxc2+,8. Kd1 Nxa1,9. b4 Bd7,10. Bb2 Ba4+,11. Kc1 Nc2,12. d4 exd4,13. exd4 d5,14. Nfd2 Bxb4,15. Nf3 Ne4,16. Ba3 Nxa3,17. Nxa3 Bxa3+,18. Kb1 Nc3+,19. Ka1 Bc2,20. Rc1 Bxc1,21. Ne5 Na4,22. Bxd5 Bb2#'
game_data_split = game_data.split(',')
#print(game_data_split)
alphabet = 'abcdefgh'
#below is just a chess board
board = [
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
]
for item in game_data_split:
#we are going to have to add something to deal with check as a boolean changing every move, or in the middle of every move if white is put in check
turn,white,black = item.split()
if white == 'O-O-O':
x = [0,1,2]
y = 0
board[x][y] += 0.1
if white.endswith('+'):
x = alphabet.index(white[-3])
y = int(white[-2]) -1
board[y][x] += 0.01
elif white.endswith('#'):
x = alphabet.index(white[-3])
y = int(white[-2]) -1
board[y][x] += 0.001
else:
x = alphabet.index(white[-2])
y = int(white[-1]) - 1
board[y][x] += 0.00001
if black == 'O-O-O':
x = [5,6,7]
y = [7]
board[y][x] += 1
if black.endswith('+'):
x = alphabet.index(black[-3])
y = int(black[-2]) -1
board[y][x] += 10
elif black.endswith('#'):
x = alphabet.index(black[-3])
y = int(black[-2]) -1
board[y][x] += 100
else:
x = alphabet.index(black[-2])
y = int(black[-1]) - 1
board[y][x] +=1000
print(turn)
pprint(board)
I am building a chess board visualizer to learn and my results seem to be coming out correctly but I keep getting results like 1e-05 or even 3.0000000000000004e-05 . I really don't want this scientific notation in my results. How can I get the printed board to stop displaying with scientific notation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在此链接中找到了答案。
只需将以下代码行放入您的程序中:
该行之后打印的任何矩阵都将抑制科学记数法。
I found the answer in this link.
Just put the following line of code in your program:
Any matrix printed after that line will have scientific notation suppressed.