电脑智能实现的原理 1。穷举所有可能的走法 2。对棋局进行评分(注:电脑智能的高低主要靠评分的合理性)。 以下代码就是对棋局评分。 Sub hqZ(ByVal arr1, ByVal fang, z) Call 人工智能2(arr1, 1, 0, arr3) Call 人工智能2(arr1, -1, 0, arr4) Dim a z = 0 For i = 1 To 10 For ii = 1 To 9 If arr1(i, ii, 1) = 1 Then z = z + arr1(i, ii, 2) If arr3(i, ii, 1) > 0 And arr4(i, ii, 1) < 1 Then z = z + 10 '如果是红色棋子,受到了自已的保护,不受黑色棋子危险 If arr3(i, ii, 1) > 0 And arr4(i, ii, 1) > 0 Then '如果是红色棋子,受自已的保护,受黑色棋子危险 If arr4(i, ii, 1) = 1 And arr1(i, ii, 2) > arr4(i, ii, 2) Then z = z - arr1(i, ii, 2) + arr4(i, ii, 2) ElseIf arr4(i, ii, 1) > 1 Then z = z - arr1(i, ii, 2) * 0.5 End If End If If arr1(i, ii, 2) = 80000 And arr4(i, ii, 1) > 0 Then z = z - 8000 '将受到危险 If arr3(i, ii, 1) < 1 And arr4(i, ii, 1) > 0 Then z = z - arr1(i, ii, 2) '如果是红色棋子,不受自已的保护,受黑色棋子危险 If arr1(i, ii, 2) = 300 And (i = 5 Or i = 6) Then z = z - 50 '相最好不要在最前线 If arr1(i, ii, 2) = 300 And (ii = 1 Or ii = 9) Then z = z - 100 '相最好不要在两边 If arr1(i, ii, 2) = 999 And ((ii = 1 And i = 1) Or (ii = 9 And i = 1)) Then z = z - 50 '出车 If arr1(i, ii, 2) = 999 And (i = 2 Or i = 5 Or i = 6 Or i = 9 Or ii = 4 Or ii = 6) Then z = z + 10 '出车 If arr1(i, ii, 2) = 100 And i > 5 And arr4(i, ii, 1) < 1 Then z = z + 80 '过河兵 If arr1(i, ii, 2) = 600 And i = 1 Then z = z - 100 '炮不要走到边上去 If arr1(i, ii, 2) = 500 And i > 5 Then z = z + 10 '过河马 If (arr1(i, ii, 2) = 400 Or arr1(i, ii, 2) = 300) And arr3(i, ii, 1) < arr4(i, ii, 1) Then z = z - 400 '保护士相 If arr1(i, ii, 2) = 80000 Then For iii = i + 1 To 10 '将不能对面 If arr1(iii, ii, 2) > 0 Then If arr1(iii, ii, 2) = 80000 Then z = z - 80000 Exit For End If Next iii End If End If If arr3(i, ii, 2) Like " * 500 * " And arr4(i, ii, 1) < 1 Then z = z + 10 '马有更多的路可走 If arr4(i, ii, 2) Like " * 500 * " And arr3(i, ii, 2) < 1 Then z = z - 10 '马有更多的路可走 If arr1(i, ii, 1) = -1 Then z = z - arr1(i, ii, 2) If arr3(i, ii, 1) > 0 And arr4(i, ii, 1) > 0 Then '如果是黑色棋子,受自已的保护,受红棋子危险 If arr4(i, ii, 1) = 1 And arr1(i, ii, 2) > arr3(i, ii, 2) Then z = z + 80 End If End If If arr3(i, ii, 1) > 0 And arr4(i, ii, 1) < 1 Then '如果是黑色棋子,不受自已的保护,受红棋子危险 z = z + 100 If arr1(i, ii, 2) = 1 Then z = z - 80 End If If arr1(i, ii, 2) = 500 And i < 6 Then z = z - 10 '过河马 If arr1(i, ii, 2) = 100 And i < 6 Then z = z - 200 '过河兵 If arr1(i, ii, 2) = 600 And i = 1 And arr3(i, ii, 1) < 1 Then '沉低炮可怕 z = z - 400 If arr(2, 5, 2) = 400 Then '沉低炮不要上士 z = z - 1000 End If End If End If Next ii Next i If arr1(3, 5, 1) = 1 And arr1(3, 5, 2) = 300 Then z = z + 20 '当中相 If arr1(1, 5, 1) = 1 And arr1(1, 5, 2) = 80000 Then z = z + 300 '将在中 If arr1(3, 4, 1) = 1 And arr1(3, 4, 2) = 600 Then z = z + 100 '仕角炮 If arr1(2, 5, 1) = 1 And arr1(2, 5, 2) = 999 Then z = z - 200 '将上车 If arr1(2, 5, 1) = 1 And arr1(2, 5, 2) = 500 Then z = z - 200 '将上马 If (arr4(2, 3, 2) Like 500 And arr3(2, 3, 1) < 1) Or (arr4(2, 7, 2) = 500 And arr3(2, 7, 1) < 1) Then z = z - 400 '不能让对方的马下来 If arr3(9, 3, 2) Like 500 Or arr3(9, 7, 2) = 500 Then z = z + 100 '自已的马过去 If arr1(4, 5, 2) = 100 And arr4(4, 5, 1) > 0 And arr3(4, 5, 1) < 1 Then z = z - 300 '保护当头兵 If arr1(4, 6, 2) = 100 Then z = z - 400 '保护当头兵 x = 0 For i = 2 To 10 '当头炮是很可怕的 If arr1(i, 5, 1) <> 0 Then x = x + 1 If arr1(i, 5, 2) = 600 And arr1(i, 5, 1) = -1 And x < 4 Then z = z - 500 Next i End Sub
[此贴子已经被作者于2006-12-4 23:30:45编辑过] |