|
2821 | 2821 | "def label_queen_conflicts(assignment,grid):\n",
|
2822 | 2822 | " ''' Mark grid with queens that are under conflict. '''\n",
|
2823 | 2823 | " for col, row in assignment.items(): # check each queen for conflict\n",
|
2824 |
| - " row_conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n", |
2825 |
| - " if temp_row == row and temp_col != col}\n", |
2826 |
| - " up_conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n", |
2827 |
| - " if temp_row+temp_col == row+col and temp_col != col}\n", |
2828 |
| - " down_conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n", |
2829 |
| - " if temp_row-temp_col == row-col and temp_col != col}\n", |
| 2824 | + " conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n", |
| 2825 | + " if (temp_row == row and temp_col != col\n", |
| 2826 | + " or (temp_row+temp_col == row+col and temp_col != col)\n", |
| 2827 | + " or (temp_row-temp_col == row-col and temp_col != col)}\n", |
2830 | 2828 | " \n",
|
2831 | 2829 | " # Place a 3 in positions where this is a conflict\n",
|
2832 |
| - " for col, row in row_conflicts.items():\n", |
2833 |
| - " grid[col][row] = 3\n", |
2834 |
| - " for col, row in up_conflicts.items():\n", |
2835 |
| - " grid[col][row] = 3\n", |
2836 |
| - " for col, row in down_conflicts.items():\n", |
| 2830 | + " for col, row in conflicts.items():\n", |
2837 | 2831 | " grid[col][row] = 3\n",
|
2838 | 2832 | "\n",
|
2839 | 2833 | " return grid\n",
|
|
0 commit comments