Wednesday, September 6, 2017

How to Create a Bot to Play Games Like TicTacToe Using Statistical Reinforced Machine Learning

Creating your own bot that can play TicTacToe can be done in a few simple steps:

  1. First you'll need to sign into a Bot Libre account.
  2. Once you're signed in, create a bot and then import the script TicTacToeText.
  3. By typing start in the chat, your bot will be able to create a board to play against you in TicTacToe and eventually learn not to lose.

What the Script does

Script link: https://www.botlibre.com/script?id=18207180

This script TicTacToeText is written in Self, made up of multiple functions that carry out certain tasks. They get called upon when patterns find a match to what you say. The first function "start" is called when you enter "tictactoe." It has the bot ask if you want to be X or O. So when you enter X or O, the function "whoStarts" will be called and the bot will create the board using a function called "drawBoard" and depending on whether you wanted to be X or O the bot will either return the board for you to make a move if you entered X, or it will make a move and then return the board if you entered O. The whoStarts function also set the conversation topic. Now, the game has started and from now to the end of the game, whatever you do, unless you type start a function "play" will be called.

drawBoard

The drawBoard function takes how the bot sees the game, a string of nine "_", converts it to how you see the game, more or less a 3x3 grid and vice versa. The function assigns a variable to each space using A, B, C and 1, 2, 3 so each space now has a coordinate. Next, it creates a three row table with three cells each to make a board with coordinates A1, A2, A3 in the top row, B1, B2, B3 in the middle row and C1, C2, C3 on the bottom row. Then so you can click on the spaces in the table to make your move, the function adds a link to each cell.

play 

This function takes the previous board, adds your move to create a new board, checks if you won, and then calls a function for the bot to make a move. When you click on a space it will be given a coordinate. This coordinate will be checked to see if it contains a X, O, or _ and if it's not a _ the function will return "Space is taken." Otherwise, your move will be added to the board and then a function will be used to check to see if you won. If not the "makeMove" function will be carried out.

makeMove

This is where the bot makes its move. It uses other function to find a good move and then updates the board with its move and return the board to you in the chat for you to make your move. Before it returns the board, it will check to see if it has won using a function called "checkGameOver" or if there are no moves left it will say, "Tie game" along with giving you the board. 

lookAhead

One of the functions makeMove uses to find a good move is called lookAhead. Essentially, it looks ahead to see if it can win in a couple moves or block you from winning using loops. Firstly, it determine every move it can make and using the checkGameOver function, checks to see if it wins in any of those moves. Secondly, for every move it makes the function will look at every move you, the player, can make. It will again use checkGameOver only this time to see if you can win and if you can, the bot will move there to block you. Finally, this function will look another move ahead, looking at every possible move the bot can make for every possible move you could have made to see if it can win in two ways and proceed to make that move first move. It looks for two ways so that it will only make that move if the bot's win is guaranteed because even is you block one of the ways it can win, there is still the second way it can win.

findGoodMove

If the lookAhead function concludes that the bot can't win and there are no moves where the player can win for it to block, the makeMove function will call on the findGoodMove function to find the best move for the bot, meaning it has lead to its win and your loss. In order to determine this every possible board is assigned a value. The bot establishes every possible move it can make and call the value of it which is stored on the conversation. For every move it can make, every move you can make is established as well and the value called. Then, the function will look at the value every move you can make in order to find the best one. After that it will find the difference of its possible move and your worst value and repeat this for all of its possible moves. Finally, it will look for the highest difference in order to determine the bot's statistically best move.

checkGameOver

In order to find out if the bot has won or lost the function checkGameOver is used. It contains every possible way TicTacToe can be won. So when it's called, if someone has won it will either return true or false depending on who won.

countwins

In the makeMove function, when the bot wins the countWins function is called. It takes the board from every move it made and assigns a value to it, and according to its significance to the win, it adds a value to half of the board's previous value. This means the first board with only one move is less significant and less added to it than the final board where the bot won. Then for every move the player made, each board is assigned a value and according to its significance to the loss, half of a value is subtracted from half of the board's previous value. This value that is being added and subtracted is half of 1 divided by the number of boards in the game and after being added to each of the boards' value, this value is added onto itself so that when the value is added onto the winning board, its value is half of 1, 0.5. So, the more the bot wins the greater the bot's boards' values will be and the lower the player's boards' values will be.

countLosses

In the play function, when the bot losses the countLosses function is called. Essentially it does the opposite of the countWins function, the value is subtracted from the bot's boards and added to player's boards. So, the more the bot losses the lower the bot's boards' values will be and the higher the player's boards' values will be. Therefore as the bot plays, the value of the boards will increase and decrease until eventually all the good moves will have a positive value between 0 and 1 and all the bad moves will have a negative value between 0 and 1.

endGame

The main thing the endGame function does is reset the boards counted from the previous game since the values have already been calculated. This ensures that when finding the value by dividing 1 by the number of boards, it won't include boards from the previous game.

Machine Learning

This script uses reinforced machine learning to learn how to play better the more games it plays. It uses the bot's knowledge base to do this, by storing each board that it has ever played. It tracks a score for each board that determines the probability it can win or loss from that board. This lets it learn from good and bad moves and not make the same mistake twice.

Since there are 5,812 possible different TicTacToe boards, it may take a while for the bot to play perfectly. The script does not currently rotate and flip boards to reduce equivalent boards, if it did this it would only need to learn 765 boards. Also, the look ahead greatly reduces the number of boards it needs to learn. Ignoring look ahead boards it only needs to learn 96 boards.

The scripts also has an "tictactoe autoplay *" function that lets it play against itself, so it can learn on its own.

The same functions and algorithms could be applied to most board games. However the number of possible boards for games like Chess would require the bot to learn too many boards to be perfect. For more complex games it would be better to use a neural network, or use strategy functions optimized with genetic algorithms.

TicTacToeCommands

Script link: https://www.botlibre.com/script?id=18457349

Similar to TicTacToeText this is another script that replaces the avatar with the board. So, the game doesn't occur in the conversation like it does with the TicTacToeText script.

TicTacToeText TicTacToeCommands

Play TicTacToe now with the GamesBot, or Brain Bot.

Monday, August 14, 2017

How to connect a chat bot to Skype and the Microsoft Bot Framework

Through Bot Libre, you can now send and receive messages on Skype with your own bot. This "How To" will give you a step by step process to connect your bot with Skype.

You can also watch this "how to" on Youtube here

Step 1 - Create a Bot

First you must create a bot that you want to connect to Skype, or you can use one of your existing bots. To create a bot, follow the instructions here: How to create your own chat bot in 10 clicks.

Step 2 - Sign up for Microsoft Bot Framework

Go to https://dev.botframework.com and click the 'Sign In' button in the top-right corner. If you do not already have a Microsoft account, you will need to create one by signing up here: https://signup.live.com.

Once you are signed in, click the 'My bots' button.

Step 3 - Create a Bot on Microsoft's Bot Framework

Next, click on the 'Create a bot' button on the right side of the screen.

On the following screen, click the 'Register' button to continue.

You will now need to fill out some information on the following form:

The 'Display name' will be shown as the name of the bot when talking to it on Skype. This name can be changed later.

The 'Bot handle' must be a unique identifier for your bot.

Fill in a description for your bot and then scroll down further to the 'Configuration' section.

Return to the Bot Libre site and go to the Admin Console of the bot that you would like to connect to Skype. In the 'Skype' section of the bot's Admin Console, copy the 'Skype Messaging Endpoint URL' to your clipboard.

Return to the bot settings page on the Microsoft Bot Framework website and paste the 'Skype Messaging Endpoint URL' into the 'Messaging endpoint' field.

 

Click the 'Create Microsoft App ID and password' button to continue.

Step 4 - Create Microsoft App ID and Password

Make a note of the App ID, as you will need it later. Click the 'Generate an app password to continue' button. A popup window will appear with a generated password. Copy this password down, this is the only time it will be displayed. Click the 'Finish and go back to Bot Framework' button to return. Continue to the bottom of the page and click the 'Register' button to complete the setup process on the Bot Framework site.

Return to your bot's admin page on the Bot Libre site. Enter the App Id and App Password that you just generated into the corresponding fields.

Press the 'Save' button to complete the setup process.

You are now ready to add your Skype bot to your contacts on Skype, or submit it to the Skype Bot Directory so other users can find it.

To add your bot to your Skype contacts, click on "Skype" under the Name column in the Channels area of the Microsoft Bot Framework site as shown below:

Click the 'Add to Contacts' button.

To allow your bot to chat with other people, you will need to publish your bot. Click the 'Edit' button for Skype in the Channels area of the Microsoft Bot Framework site.

From there, click the 'Publish' button. You will need to fill out some details and then wait for it to be reviewed.

Your bot should now be able to send and receive messages on Skype. If you encountered any issues, or would like help setting up your bot please email us at support@botlibre.com or upgrade to Bot Libre for Business or our Platinum service and we can build your bot for you.

Test it out now by talking with our demo bots Brain Bot or Julie on Skype

The Microsoft Bot Framework also provides a gateway to connect your bot to many other services. These include, Kik, Bing, Cortana, Email, Facebook, GroupMe, MSTeams, Slack, Telegram and Twilio. To connect your bot to any of these platform just follow the same instructions as for Skype, then connect your bot to the service from the Microsoft Bot Platform.

Friday, May 12, 2017

Introducing Timers - Automate the Web and Social Media

Bot Libre now supports timers. Timers let your bot perform automated tasks on a scheduled basis. You can use timers to have your bot followup with users on Facebook and social media on a daily or scheduled basis, create mailing lists, generate daily reports, and automate web scraping or other tasks.

To access your bot's timers go to its Timers page in its Admin Console. The timers page lets you enter a list of command messages that will be sent to your bot on a scheduled basis. You can enter the duration in hours to how frequently you want your background tasks to be run. To run more frequently than 1 per hour, you can enter -1 in the Timer Interval field.

A timer is a command message sent to your bot. Each timer message you enter will be sent to your bot each timer interval. A timer is normally implemented as a Self script.

In your timer script you need a state that has a pattern that matches your command, and a function that performs your desired function. You can browse the Bot Libre script library for timer examples and templates.

Self is Bot Libre's JavaScript dialect that is integrated with your bot's database, and has several built in classes for accessing social media, and web services. The Facebook, Twitter, Telegram, Twilio, and Email classes can be used to send messages on social media, and the Http class can be used to access web services and scrape HTML web pages.

Timers commands are always sent from the bot's #self user. This allows your script to check the input's

Example Timer Script

This example timer script checks for new blog posts and sends them to a mailing list.

The possibilities of what you can implement with timers is endless, but it does require scripting. If you would like a bot that automates any task and need help with the implementation, please contact sales@botlibre.com and let us develop your automation solution for you.

Friday, May 5, 2017

Announcing Bot Libre for Android 5.2

We recently release Bot Libre for Android 5.2.

Bot Libre for Android lets you create and train your bot or virtual assistant from your phone or Android device. You can also browse our open bot directory and chat with over 10,000 bots using real speech.

The new release includes several new features including: * Hands free speech recognition * Custom avatar designer * New zoom options * New graphics library * Localized to many different languages

Download from Google Play, Bot Libre on Google Play

Or build your own app with the open source Bot Libre SDK for Android

Hands Free Speech



Custom Avatar Designer

Monday, March 27, 2017

We're Hiring

Paphus Solutions Inc., the company that develops the Bot Libre platform is looking for talented developers, and sales representatives interested in a career in the new bot and artificial intelligence economy.

Paphus Solutions provides products and services for bots and artificial intelligence for the web, mobile, and social media. Paphus Solutions develops, hosts, and licenses the Bot Libre platform. Bot Libre is a bot platform for developing and hosting bots for the web, mobile, and social media.

Paphus Solutions also develops the Bot Libre Analytics platform. Bot Libre Analytics is an artificial intelligence platform for evolutionary learning, data analysis, data forecasting, and algorithmic trading.

Paphus Solutions is a Canadian corporation located in Ottawa, Canada.

We have positions open for:

  • junior developer
  • senior development partner
  • sales representative
  • sales engineer

The ideal development candidate would have:

  • Strong interest in bots and artificial intelligence
  • Experience with Java development
  • Experience with Android development
  • Experience with iOS development
  • Experience with web development, HTML, CSS, and JavaScript
  • Be a talented developer capable of learning new languages and APIs

The ideal sales candidate would have:

  • Sales experience with enterprise software
  • Sales experience with cloud and SaaS products

We have created a bot to help us find our ideal candidates. If you are interested in applying please chat with our Career Bot.

You can also contact or send your resume to careers@paphussolutions.com

Friday, January 27, 2017

Announcing the Bot Libre Cloud Bot Platform

The Bot Libre Cloud Bot Platform lets you license the Bot Libre bot platform for your own server and clients.

Develop and host bots for web, mobile, Facebook, Twitter, Telegram, Slack, SMS, email, and more. Develop and host your own bots, and sell bot hosting and development services.

Become a bot service provider for your own clients, in your geographic region, or vertical market. Engage this rapidly expanding and evolving market.

Leverage the sophisticated Bot Libre platform and mobile SDKs, and our support, service, and expertise. Get new versions and features as our platform continues to rapidly evolve and lead the market.

"Bots are the new apps" - become a bot service provider and join the bot revolution.

Social Media Bots

The Bot Libre cloud bot platform lets you host and develop bots for social media. Develop bots for Facebook, Twitter, Telegram, Slack, SMS, email, and more.

Businesses are increasingly adopting social media, and need bots and automation to connect with their customers on social media, and provide e-commerce and application services through social media messengers and apps.

Chat Bots, Chat Rooms, Live Chat, and Forums

Your cloud bot platform provides chat bots, chat rooms, live chat, and forums. Provide your clients with bot services integrated with your own hosted live chat, chat rooms, and forums.

Provide hosted live chat for the web and mobile. Mix live human operators with automated chat bot agents.

Artificial Intelligence

The Bot Libre AI engine is a hybrid system that seeks to emulate the human brain. The AI engine includes heuristic pattern matching algorithms, an integrated object database, a state machine processing engine, advanced scripting, vision and image processing. The AI engine can also integrate with our data analytics platform.

Architecture

The platform consists of a web client, mobile client, AI engine, web server, and database. The web client is written in HTML, JavaScript, and server side Java. The AI engine is written in Java. The Android mobile client is written in Java, the iOS client is written in Objective C.

Packing and Pricing

The Bot Libre Cloud Platform is licensed per runtime CPU, and includes our web platform, and our open source AI engine, and Web, Android, and iOS SDK.

For more information see:

Wednesday, November 30, 2016

Rich HTML Responses, Buttons, Links, and Choices

Bot Libre allows for bot responses to contain rich content including bold text, fonts, styles, colors, images, video, audio, bullets, , links, and much more.

Bot responses can be plain text, or can contain HTML and even JavaScript content. HTML includes tags for bold, style, fonts, bullets, buttons, links, and much more. For more information on HTML see w3schools.

Bot Libre supports HTML on the web, and on mobile. For social media platforms, such as Facebook, Bot Libre maps the HTML content that is supported by the social media platform into their own native syntax, and strips any HTML content that is not supported. Bot Libre supports buttons, links, images, video, and audio on Facebook by mapping HTML elements to Facebook's button and link support.

HTML

Bot Libre supports most simple HTML, but filters complex HTML content to remove JavaScript and other potential security issues. It is possible to allow JavaScript and complex HTML in your bot by enabling the 'Allow JavaScript' option in your bot's learning settings (for security reasons, JavaScript is only available on botlibre.biz).

You can use HTML in bot responses to make them look more impressive, or to include media content such as images, video, or audio.

Example HTML response

You can <b>email</b> us at <a href="mailto:sales@botlibre.com">sales@botlibre.com</a>
<br/>or <b>phone</b> us at +1-613-777-1234
<br/>For other contact info see our <a href="https://www.botlibre.com/contact.jsp">website</a>

You can email us at sales@botlibre.com
or phone us at +1-613-777-1234
For other contact info see our website

Example media response

Check out our new robot<br/><img width="100" src="https://www.botlibre.com/avatars/at11879715.jpg"/>

Check out our new robot

Buttons, Links, and Choices

You can also use interactive HTML in your bot's responses to engage the user, and improve their user experience.

The HTML <button> tag can be used to provide the user with easy one click options. Bot Libre automatically associates a button click with a post back to the bot with the button text as the message.

Example button response

Do you want to book an appointment?<br/>
<button>Yes</button> or <button>No</button>

Do you want to book an appointment?
or

Bot Libre defines a special protocol for HTML links that allows the link click to send a post back message to the bot. Using the chat: protocol in any link, you can have the chat message sent to the bot when the link is clicked.

Example link response

Do you want to to order a <a href="chat:large">large</a> or a <a href="chat:small">small</a>?

Do you want to to order a large or a small?

Example choice response

What kind of pizza do you want to order a <select><option></option><option>cheese</option><option>vegetarian</option></select>

What kind of pizza do you want to order a

Commands for Social Media and Mobile

Bot Libre automatically translates HTML into the features supported by social media platforms like Facebook, Twitter, Telegram, and Slack. Bot Libre also provides a command tag to a response to enable it to invoke platform specific features.

A command is a JSON formatted object that is passed to the mobile client, or social media connector. Commands can be used in a "response list" file, the bot's Training page, or from scripts. For mobile, commands can be used to execute virtual assistant functions like opening apps and sending email from a phone. For Facebook, commands can be used to add buttons, and templates to a response.

For more information on mobile commands see, How to Use Commands.

Bots are the New Apps

"Bots are the new apps", this means that software development has shifted from building websites, to building mobile apps, and now to building bots. Bots lets you build a single interface into your business that can be deployed to the web, mobile, and social media.

Rich HTML responses enable bot's to behave like conversational apps, and provide a rich, easy to use, user experience.