GotAI.NET

Форум: Проблемы искусственного интеллекта

 

Регистрация | Вход

 Все темы | Новая тема Стр.2 (2)<< < Пред.   Поиск:  
 Автор Тема: На: Игровой ИИ
гость
192.95.40.*
На: Игровой ИИ
Добавлено: 09 апр 23 6:45
Код на C# крестики нолики


using System;

class TicTacToe {
static char[] board = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
static char player = 'X';

static void Main() {
Console.WriteLine("Welcome to Tic Tac Toe!");

while (true) {
Console.WriteLine("Current board:");
print_board();
if (check_win('X')) {
Console.WriteLine("X wins!");
break;
} else if (check_win('O')) {
Console.WriteLine("O wins!");
break;
} else if (get_actions().Length == 0) {
Console.WriteLine("Tie game!");
break;
}

if (player == 'X') {
Console.WriteLine("X's turn.");
int index = int.Parse(Console.ReadLine()) - 1;
if (board[index] == 'X' || board[index] == 'O') {
Console.WriteLine("Invalid move, try again.");
continue;
}
board[index] = 'X';
player = 'O';
} else {
Console.WriteLine("O's turn.");
int index = get_best_action();
board[index] = 'O';
player = 'X';
}
}
}

static void print_board() {
Console.WriteLine("{0} | {1} | {2}", board[0], board[1], board[2]);
Console.WriteLine("--+---+--");
Console.WriteLine("{0} | {1} | {2}", board[3], board[4], board[5]);
Console.WriteLine("--+---+--");
Console.WriteLine("{0} | {1} | {2}", board[6], board[7], board[8]);
}

static bool check_win(char player) {
for (int i = 0; i < 9; i += 3) {
if (board[i] == player && board[i+1] == player && board[i+2] == player) {
return true;
}
}
for (int i = 0; i < 3; i++) {
if (board[i] == player && board[i+3] == player && board[i+6] == player) {
return true;
}
}
if (board[0] == player && board[4] == player && board[8] == player) {
return true;
}
if (board[2] == player && board[4] == player && board[6] == player) {
return true;
}
return false;
}

static int[] get_actions() {
int count = 0;
for (int i = 0; i < 9; i++) {
if (board[i] != 'X' && board[i] != 'O') {
count++;
}
}
int[] actions = new int[count];
count = 0;
for (int i = 0; i < 9; i++) {
if (board[i] != 'X' && board[i] != 'O') {
actions[count] = i;
count++;
}
}
return actions;
}

static int get_best_action() {
int[] actions = get_actions();
Random random = new Random();
int index = random.Next(actions.Length);
return actions[index];
}
}

[Ответ][Цитата]
Matrix
Сообщений: 1645
На: Игровой ИИ
Добавлено: 17 май 23 8:02
Изменено: 17 май 23 8:09
вот так выглядит ядро нейросети
4784 All BASIC

    Private Sub AI(w)
Randomize()
Dim r = (Int(Rnd() * 14) + 1)
Dim s = ""
Dim i = 1, j
Dim word = ""
Dim wq

word = w 'kw((Int(Rnd() * wn) + 1))
Do

For j = 1 To 250
Randomize()
If (Int(Rnd() * 11) + 1) = 1 Then

word = kw((Int(Rnd() * wn) + 1))
wq = Word_Qu(word)
If (wq >= 2) Then
If ((Int(Rnd() * wn) + 1) <> wq) Then Continue For
End If
Else
Build_Links(word)
Dim rlw = links((Int(Rnd() * link_n) + 1))
If (Int(Rnd() * 2) + 1) = 1 And word <> rlw Then word = rlw Else Continue For
wq = Word_Qu(word)
If (wq >= 2) Then
If ((Int(Rnd() * wn) + 1) <> wq) Then Continue For
End If
End If
Exit For
Next

last_w = word

s = s + word + " "
i = i + 1

Loop While (i <= r)

name_AI = "AI- "

AddToLog(name_AI + s)
RichTextBox2.AppendText(name_AI + s & vbCrLf)
RichTextBox2.ScrollToCaret()

TextBegin(s)
While TextReadWord()
Add_To_Kw(g_text_word)
End While
Save_KW()


CreateObject("SAPI.SpVoice").Speak(s)

Label1.Text = wn

End Sub


    Sub Build_Links(w)
link_n = 0
Dim i = 1
Do
If kw(i) = w Then link_n = link_n + 1 : links(link_n) = kw(i + 1)
i = i + 1
Loop While (i <= (wn - 1))
End Sub
[Ответ][Цитата]
sam
Сообщений: 36
На: Игровой ИИ
Добавлено: 27 сен 23 3:28
Опаньки какая прелесть, код даже кто то написал...

Нужно както времени найти новым вглядом старый свой проект с игровым ИИ порефакторить
[Ответ][Цитата]
 Стр.2 (2)1  [2]<< < Пред.